]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/10_terminal/10_terminal.zshrc
10_terminal: Add command to window title in iTerm.app
[ax-zsh.git] / core / 10_terminal / 10_terminal.zshrc
index 56de7c0fbd29984ed94e58b8d9929acfffd39c3b..fa27ed7f5919502d092e1015f08fca2b8b75a67c 100644 (file)
@@ -32,24 +32,36 @@ precmd_functions+=(axzsh_terminal_title_precmd)
 # Update terminal titles befor executing a command
 function axzsh_terminal_title_preexec {
        local cmd="${1[(w)1]}"
+       local remote=""
+       case "$cmd" in
+         "mosh"*|"ssh"*|"telnet"*)
+               remote=1
+               ;;
+       esac
        if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
                # Apple Terminal.app ...
-               case "$cmd" in
-                 "mosh"*|"ssh"*|"telnet"*)
+               if [[ -n "$remote" ]]; then
                        # Reset CWD for remote commands
                        printf '\e]7;%s\a' ''
-                       ;;
-               esac
+               fi
        fi
+       if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
+               # iTerm.app ...
+               [[ -n "$cmd" ]] && TITLE_ADD=" – $cmd"
+       fi
+
        axzsh_terminal_set_icon_title "$cmd"
-       axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
+
+       [[ -z "$remote" ]] \
+               && axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" \
+               || axzsh_terminal_set_window_title "$1"
 }
 
 preexec_functions+=(axzsh_terminal_title_preexec)
 
 # Colors
 
-autoload -U colors
+autoload -Uz colors
 colors
 
 # Text effects (FX)