fix(lib): fix automatic title abort inside Emacs (#10124)
Closes #10124
Co-authored-by: Paul Schorfheide <pschorf2@gmail.com>
Co-authored-by: Alastair Rankine <alastair@girtby.net>
Diff
1diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
2index 33451ef1f93c2b496eff295741733ca83dc8dfaa..ef0d78895b019888bb01e35751a18ea72f03f8ed 100644
3--- a/lib/termsupport.zsh
4+++ b/lib/termsupport.zsh
5@@ -10,7 +10,8 @@ function title {
6 emulate -L zsh
7 setopt prompt_subst
8 9- [[ "$INSIDE_EMACS" == *term* ]] && return
10+ # Don't set the title if inside emacs, unless using vterm
11+ [[ -n "$INSIDE_EMACS" && "$INSIDE_EMACS" != vterm ]] && return
1213 # if $2 is unset use $1 as default
14 # if it is set and empty, leave it as is
15@@ -29,12 +30,9 @@ function title {
16 print -Pn "\e]2;${2:q}\a" # set window name
17 print -Pn "\e]1;${1:q}\a" # set tab name
18 else
19- # Try to use terminfo to set the title
20- # If the feature is available set title
21- if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
22- echoti tsl
23- print -Pn "$1"
24- echoti fsl
25+ # Try to use terminfo to set the title if the feature is available
26+ if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
27+ print -Pn "${terminfo[tsl]}$1${terminfo[fsl]}"
28 fi
29 fi
30 ;;
31@@ -105,10 +103,12 @@ function omz_termsupport_preexec {
32 title '$CMD' '%100>...>$LINE%<<'
33 }
3435-autoload -U add-zsh-hook
36-add-zsh-hook precmd omz_termsupport_precmd
37-add-zsh-hook preexec omz_termsupport_preexec
38+autoload -Uz add-zsh-hook
3940+if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then
41+ add-zsh-hook precmd omz_termsupport_precmd
42+ add-zsh-hook preexec omz_termsupport_preexec
43+fi
4445 # Keep Apple Terminal.app's current working directory updated
46 # Based on this answer: https://superuser.com/a/315029