]> arthur.barton.de Git - ax-zsh.git/commitdiff
10_terminal: Rework window title, tab title, and hardstatus handling
authorAlexander Barton <alex@barton.de>
Sun, 19 Jul 2015 23:09:43 +0000 (01:09 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 19 Jul 2015 23:09:43 +0000 (01:09 +0200)
Now the result should be more consistent and useful:

- Apple Terminal.app: The current working directory is set for local
  commands and removed for remote commands (mosh, ssh, telnet).

- The "window title" is set to "user@host", and the working directory is
  added when not using Apple Terminal.app or a remote shell.

- The "icon title" (used for "tabulator titles" in most current terminal
  emulators) and "hardstatus" (used by screen(1)) is set to the command
  name only.

core/10_terminal/10_terminal.zshrc

index 7a5538db88f81e50ae45129fd48bd7beaa834acb..56de7c0fbd29984ed94e58b8d9929acfffd39c3b 100644 (file)
@@ -3,18 +3,50 @@
 
 # Set terminal title
 
+# Set terminal "hardstatus" and "icon title"
+function axzsh_terminal_set_icon_title {
+       [[ "$TERM" == "screen"* ]] && printf '\ek%s\e\\' "$1"
+       printf '\e]1;%s\a' "$1"
+}
+
+# Set terminal window title
+function axzsh_terminal_set_window_title {
+       printf '\e]2;%s\a' "$1"
+}
+
+# Update terminal titles befor echoing the shell prompt
 function axzsh_terminal_title_precmd {
-       if [[ $TERM_PROGRAM == Apple_Terminal ]]; then
+       axzsh_terminal_set_icon_title 'zsh'
+       if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
+               axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
+               # Update CWD in Terminal.app
                local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g')
                printf '\e]7;%s\a' "$url"
-               printf '\e]0;%s\a' "$LOGNAME@$SHORT_HOST"
        else
-               printf '\e]0;%s\a' "$LOGNAME@$SHORT_HOST:$PWD"
+               axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST:$PWD"
        fi
 }
 
 precmd_functions+=(axzsh_terminal_title_precmd)
 
+# Update terminal titles befor executing a command
+function axzsh_terminal_title_preexec {
+       local cmd="${1[(w)1]}"
+       if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
+               # Apple Terminal.app ...
+               case "$cmd" in
+                 "mosh"*|"ssh"*|"telnet"*)
+                       # Reset CWD for remote commands
+                       printf '\e]7;%s\a' ''
+                       ;;
+               esac
+       fi
+       axzsh_terminal_set_icon_title "$cmd"
+       axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
+}
+
+preexec_functions+=(axzsh_terminal_title_preexec)
+
 # Colors
 
 autoload -U colors