Browse Source

Update zsh prompt (update window title using preexec and precmd)

Emmanuel Bouthenot 12 years ago
parent
commit
fa8a9711a0
1 changed files with 23 additions and 2 deletions
  1. 23 2
      .zsh.d/config.d/prompt.zsh

+ 23 - 2
.zsh.d/config.d/prompt.zsh

@@ -82,9 +82,30 @@ pr_git_prompt() {
     echo -n "${git_prompt}"
     echo -n "${git_prompt}"
 }
 }
 
 
-function preexec {}
+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
+}
 
 
-function precmd {}
+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
+}
 
 
 myprompt() {
 myprompt() {
     if [ "$TERM" = "dumb" ]; then
     if [ "$TERM" = "dumb" ]; then