Skip to content

Commit adabd26

Browse files
author
xaos
committed
use oh-my-zsh title() function to support more terminals
1 parent a8033e0 commit adabd26

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

geometry.zsh

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,57 @@ geometry::hostcolor() {
6363
echo ${colors[${index}]}
6464
}
6565

66+
# Set terminal window and tab/icon title
67+
#
68+
# usage: title short_tab_title [long_window_title]
69+
#
70+
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
71+
# Fully supports screen, iterm, and probably most modern xterm and rxvt
72+
# (In screen, only short_tab_title is used)
73+
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
74+
geometry::echo_title_sequence() {
75+
emulate -L zsh
76+
setopt prompt_subst
77+
78+
[[ "$INSIDE_EMACS" == *term* ]] && return
79+
80+
# if $2 is unset use $1 as default
81+
# if it is set and empty, leave it as is
82+
: ${2=$1}
83+
84+
case "$TERM" in
85+
cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*)
86+
print -Pn "\e]2;${2:q}\a" # set window name
87+
print -Pn "\e]1;${1:q}\a" # set tab name
88+
;;
89+
screen*|tmux*)
90+
print -Pn "\ek${1:q}\e\\" # set screen hardstatus
91+
;;
92+
*)
93+
if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
94+
print -Pn "\e]2;${2:q}\a" # set window name
95+
print -Pn "\e]1;${1:q}\a" # set tab name
96+
else
97+
# Try to use terminfo to set the title
98+
# If the feature is available set title
99+
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
100+
echoti tsl
101+
print -Pn "$1"
102+
echoti fsl
103+
fi
104+
fi
105+
;;
106+
esac
107+
}
108+
66109
# set cmd title (while command is running)
67110
geometry::set_cmdtitle() {
68111
# Make command title available for optional consumption by geometry_cmd
69112
GEOMETRY_LAST_CMD=$2
70113
local ansiCmdTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_CMDTITLE))
71114
local cmdTitle=$(deansi "$ansiCmdTitle")
72115

73-
echo -ne "\e]1;$cmdTitle\a"
116+
geometry::echo_title_sequence "$cmdTitle"
74117
}
75118
add-zsh-hook preexec geometry::set_cmdtitle
76119

@@ -79,7 +122,7 @@ geometry::set_title() {
79122
local ansiTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_TITLE))
80123
local title=$(deansi "$ansiTitle")
81124

82-
echo -ne "\e]1;$title\a"
125+
geometry::echo_title_sequence "$title"
83126
}
84127
add-zsh-hook precmd geometry::set_title
85128

0 commit comments

Comments
 (0)