# 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