1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # 10_terminal.zshrc: Initialize terminal settings
6 # Set terminal "hardstatus" and "icon title"
7 function axzsh_terminal_set_icon_title {
8 [[ "$TERM" == "screen"* ]] && printf '\ek%s\e\\' "$1"
9 printf '\e]1;%s\a' "$1"
12 # Set terminal window title
13 function axzsh_terminal_set_window_title {
14 printf '\e]2;%s\a' "$1"
17 # Update terminal titles befor echoing the shell prompt
18 function axzsh_terminal_title_precmd {
19 axzsh_terminal_set_icon_title 'zsh'
20 if [[ "$TERM_PROGRAM" == "Apple_Terminal" && "$TERM" != "screen"* ]]; then
21 axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
22 # Update CWD in Terminal.app
23 local url=$(echo "file://$HOSTNAME$PWD" | sed -e 's| |%20|g')
24 printf '\e]7;%s\a' "$url"
26 axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST:$PWD"
30 precmd_functions+=(axzsh_terminal_title_precmd)
32 # Update terminal titles befor executing a command
33 function axzsh_terminal_title_preexec {
34 local cmd="${1[(w)1]}"
35 if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
36 # Apple Terminal.app ...
38 "mosh"*|"ssh"*|"telnet"*)
39 # Reset CWD for remote commands
44 axzsh_terminal_set_icon_title "$cmd"
45 axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST"
48 preexec_functions+=(axzsh_terminal_title_preexec)