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]}"
37 "mosh"*|"ssh"*|"telnet"*)
41 if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]]; then
42 # Apple Terminal.app ...
43 if [[ -n "$remote" ]]; then
44 # Reset CWD for remote commands
48 if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
50 [[ -n "$cmd" ]] && TITLE_ADD=" – $cmd"
53 axzsh_terminal_set_icon_title "$cmd"
56 && axzsh_terminal_set_window_title "$LOGNAME@$SHORT_HOST$TITLE_ADD" \
57 || axzsh_terminal_set_window_title "$1"
60 preexec_functions+=(axzsh_terminal_title_preexec)