]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/10_terminal/10_terminal.zshrc
10_terminal: Rework window title, tab title, and hardstatus handling
[ax-zsh.git] / 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