]> arthur.barton.de Git - ax-zsh.git/blobdiff - core/10_terminal/10_terminal.zshrc
Use "autoload -Uz"
[ax-zsh.git] / core / 10_terminal / 10_terminal.zshrc
index 5ac08f79c9c46227e5bb2457d38f2dc9d39b1696..e300e757ac2e7421b0ba80e635af0e02c6721c6b 100644 (file)
@@ -3,26 +3,53 @@
 
 # Set terminal title
 
-function axzsh_terminal_precmd {
-       printf '\e]1;%s\a' "$LOGNAME@$SHORT_HOST"
+# 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"
 }
 
-precmd_functions+=(axzsh_terminal_precmd)
-
-# Set current working directory
+# Set terminal window title
+function axzsh_terminal_set_window_title {
+       printf '\e]2;%s\a' "$1"
+}
 
-function axzsh_terminal_cwd {
-       if [[ $TERM_PROGRAM == Apple_Terminal ]]; then
-               local url="file://$HOSTNAME${PWD// /%20}"
+# Update terminal titles befor echoing the shell prompt
+function axzsh_terminal_title_precmd {
+       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"
+       else
+               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"
 }
 
-precmd_functions+=(axzsh_terminal_cwd)
+preexec_functions+=(axzsh_terminal_title_preexec)
 
 # Colors
 
-autoload -U colors
+autoload -Uz colors
 colors
 
 # Text effects (FX)