Browse Source

Update zsh prompt to make it work on various TERMs

Emmanuel Bouthenot 11 years ago
parent
commit
0c3928dcdd
1 changed files with 31 additions and 24 deletions
  1. 31 24
      .zsh.d/config.d/prompt.zsh

+ 31 - 24
.zsh.d/config.d/prompt.zsh

@@ -68,10 +68,10 @@ pr_git_prompt() {
         local cached=$(git diff --cached --name-only | wc -l)
         git_prompt="${PR_YELLOW}${branch}${PR_NO_COLOR}"
         if [ "$modified" -gt 0 ]; then
-            git_prompt="${git_prompt} ${PR_RED}${modified}${PR_NO_COLOR}"
+            git_prompt="${git_prompt} ${PR_RED}${modified}${PR_NO_COLOR}±"
         fi
         if [ "$cached" -gt 0 ]; then
-            git_prompt="${git_prompt} ${PR_LIGHT_GREEN}${cached}${PR_NO_COLOR}"
+            git_prompt="${git_prompt} ${PR_LIGHT_GREEN}${cached}${PR_NO_COLOR}±"
         fi
         local commits=$(git rev-list --no-merges --count origin/${branch}..${branch} 2>/dev/null)
         if [ "$commits" -gt 0 ]; then
@@ -82,29 +82,37 @@ pr_git_prompt() {
     echo -n "${git_prompt}"
 }
 
-function preexec {
-    # get the command basename
-    local cmd=${1##*\/}
-    if [ -n "${SSH_CLIENT}" ]; then
-        cmd="%n@%M: ${cmd}"
-    fi
-    if [ -n "$TMUX" ]; then
-        print -Pn "\ek%-3 ${cmd}\e"
-    else
-        print -Pn "\e]0;${cmd}\a"
-    fi
+preexec() {
+    case "$TERM" in
+        xterm*|screen*)
+            # get the command basename
+            local cmd=${1##*\/}
+            if [ -n "${SSH_CLIENT}" ]; then
+                cmd="%n@%M: ${cmd}"
+            fi
+            if [ -n "$TMUX" ]; then
+                print -Pn "\033k\033\134\033k${cmd}\033\134"
+            else
+                print -Pn "\e]0;${cmd}\a"
+            fi
+            ;;
+    esac
 }
 
-function precmd {
-    local cmd="%~"
-    if [ -n "${SSH_CLIENT}" ]; then
-        cmd="%n@%M: ${cmd}"
-    fi
-    if [ -n "$TMUX" ]; then
-        print -Pn "\ek%-3 ${cmd}\e"
-    else
-        print -Pn "\e]0;${cmd}\a"
-    fi
+precmd() {
+    case "$TERM" in
+        xterm*|screen*)
+            local cmd="%~"
+            if [ -n "${SSH_CLIENT}" ]; then
+                cmd="%n@%M: ${cmd}"
+            fi
+            if [ -n "$TMUX" ]; then
+                print -Pn "\ek%-3 ${cmd}\e"
+            else
+                print -Pn "\e]0;${cmd}\a"
+            fi
+        ;;
+    esac
 }
 
 myprompt() {
@@ -128,4 +136,3 @@ ${PR_WHITE} using ${PR_OS_NAME}
 }
 
 myprompt
-