From adabd269e7d7d531ac54768bbfb824dd89c1ef5e Mon Sep 17 00:00:00 2001 From: xaos Date: Mon, 8 Feb 2021 12:07:56 +0100 Subject: [PATCH 1/2] use oh-my-zsh title() function to support more terminals --- geometry.zsh | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/geometry.zsh b/geometry.zsh index 19730ff..773d803 100644 --- a/geometry.zsh +++ b/geometry.zsh @@ -63,6 +63,49 @@ 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) +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 +113,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 +122,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 From 079ef5431d419265e52cb8019750d9691313974a Mon Sep 17 00:00:00 2001 From: xaos Date: Wed, 7 Jul 2021 21:30:24 +0200 Subject: [PATCH 2/2] include link to the original --- geometry.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/geometry.zsh b/geometry.zsh index 773d803..8900824 100644 --- a/geometry.zsh +++ b/geometry.zsh @@ -71,6 +71,9 @@ geometry::hostcolor() { # 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