diff --git a/geometry.zsh b/geometry.zsh index 19730ff..8900824 100644 --- a/geometry.zsh +++ b/geometry.zsh @@ -63,6 +63,52 @@ geometry::hostcolor() { echo ${colors[${index}]} } +# Set terminal window and tab/icon title +# +# usage: title short_tab_title [long_window_title] +# +# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1 +# Fully supports screen, iterm, and probably most modern xterm and rxvt +# (In screen, only short_tab_title is used) +# Limited support for Apple Terminal (Terminal can't set window and tab separately) + +# This is the title() function taken directly from oh-my-zsh +# https://github.com/ohmyzsh/ohmyzsh/blob/c44b99e901d7ef58f60247995152de1b937e2e9c/lib/termsupport.zsh +geometry::echo_title_sequence() { + emulate -L zsh + setopt prompt_subst + + [[ "$INSIDE_EMACS" == *term* ]] && return + + # if $2 is unset use $1 as default + # if it is set and empty, leave it as is + : ${2=$1} + + case "$TERM" in + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*) + print -Pn "\e]2;${2:q}\a" # set window name + print -Pn "\e]1;${1:q}\a" # set tab name + ;; + screen*|tmux*) + print -Pn "\ek${1:q}\e\\" # set screen hardstatus + ;; + *) + if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then + print -Pn "\e]2;${2:q}\a" # set window name + print -Pn "\e]1;${1:q}\a" # set tab name + else + # Try to use terminfo to set the title + # If the feature is available set title + if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then + echoti tsl + print -Pn "$1" + echoti fsl + fi + fi + ;; + esac +} + # set cmd title (while command is running) geometry::set_cmdtitle() { # Make command title available for optional consumption by geometry_cmd @@ -70,7 +116,7 @@ geometry::set_cmdtitle() { local ansiCmdTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_CMDTITLE)) local cmdTitle=$(deansi "$ansiCmdTitle") - echo -ne "\e]1;$cmdTitle\a" + geometry::echo_title_sequence "$cmdTitle" } add-zsh-hook preexec geometry::set_cmdtitle @@ -79,7 +125,7 @@ geometry::set_title() { local ansiTitle=$(print -P $(geometry::wrap $PWD $GEOMETRY_TITLE)) local title=$(deansi "$ansiTitle") - echo -ne "\e]1;$title\a" + geometry::echo_title_sequence "$title" } add-zsh-hook precmd geometry::set_title