From 8d23fbd6964b8446bbc73ff04507362d1fd49eb5 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Tue, 4 Apr 2023 16:47:13 +0200 Subject: feat(termsupport): add contour terminal (#11599) Signed-off-by: Christian Parpart --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 80ca7ef78..5bc418761 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]1;${1:q}\a" # set tab name ;; -- cgit v1.2.3-70-g09d2 From 25c2c3a4683be60c3526858be960ee6ce1249245 Mon Sep 17 00:00:00 2001 From: Alexander Schlarb Date: Sun, 16 May 2021 18:58:38 +0200 Subject: feat(lib): send OSC 7 on directory change for more supported terminals (#9914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously this was only emitted on macOS with Apple's Terminal.app (and compatible clones like iTerm2), but it is used by other terminal emulators as well to obtain the actual current working directory wiht symlinks intact. All non-supporting terminal emulators tested gracefully ignored this value, so emit this on these as well in case they (or some other app masquarading as them) add future support for this value. Closes #9914 Co-authored-by: Marc Cornellà --- lib/termsupport.zsh | 72 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 24 deletions(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 5bc418761..cf8f08741 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -109,28 +109,52 @@ if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then add-zsh-hook preexec omz_termsupport_preexec fi -# Keep Apple Terminal.app's current working directory updated -# Based on this answer: https://superuser.com/a/315029 -# With extra fixes to handle multibyte chars and non-UTF-8 locales - -if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then - # Emits the control sequence to notify Terminal.app of the cwd - # Identifies the directory using a file: URI scheme, including - # the host name to disambiguate local vs. remote paths. - function update_terminalapp_cwd() { - emulate -L zsh - - # Percent-encode the host and path names. - local URL_HOST URL_PATH - URL_HOST="$(omz_urlencode -P $HOST)" || return 1 - URL_PATH="$(omz_urlencode -P $PWD)" || return 1 - - # Undocumented Terminal.app-specific control sequence - printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH" - } - - # Use a precmd hook instead of a chpwd hook to avoid contaminating output - add-zsh-hook precmd update_terminalapp_cwd - # Run once to get initial cwd set - update_terminalapp_cwd +# Keep terminal emulator's current working directory correct, +# even if the current working directory path contains symbolic links +# +# References: +# - Apple's Terminal.app: https://superuser.com/a/315029 +# - iTerm2: https://iterm2.com/documentation-escape-codes.html (iTerm2 Extension / CurrentDir+RemoteHost) +# - Konsole: https://bugs.kde.org/show_bug.cgi?id=327720#c1 +# - libvte (gnome-terminal, mate-terminal, …): https://bugzilla.gnome.org/show_bug.cgi?id=675987#c14 +# Apparently it had a bug before ~2012 were it would display the unknown OSC 7 code +# +# As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC. + +# Don't define the function if we're inside Emacs +if [[ -n "$INSIDE_EMACS" ]]; then + return fi + +# Don't define the function if we're in an unsupported terminal +case "$TERM" in + # all of these either process OSC 7 correctly or ignore entirely + xterm*|putty*|rxvt*|konsole*|mlterm*|alacritty|screen*|tmux*) ;; + contour*|foot*) ;; + *) + # Terminal.app and iTerm2 process OSC 7 correctly + case "$TERM_PROGRAM" in + Apple_Terminal|iTerm.app) ;; + *) return ;; + esac ;; +esac + +# Emits the control sequence to notify many terminal emulators +# of the cwd +# +# Identifies the directory using a file: URI scheme, including +# the host name to disambiguate local vs. remote paths. +function omz_termsupport_cwd { + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(omz_urlencode -P $HOST)" || return 1 + URL_PATH="$(omz_urlencode -P $PWD)" || return 1 + + # common control sequence (OSC 7) to set current host and path + printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" +} + +# Use a precmd hook instead of a chpwd hook to avoid contaminating output +# i.e. when a script or function changes directory without `cd -q`, chpwd +# will be called the output may be swallowed by the script or function. +add-zsh-hook precmd omz_termsupport_cwd -- cgit v1.2.3-70-g09d2 From 50c678687e73d1433f278b7bb7f168e8fa817670 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 8 Jun 2023 18:47:05 +0200 Subject: fix(termsupport): fix pwd report for Konsole (#11730) The Konsole terminal shows an error if the host is provided in the OSC 7 sequence. Fixes #11730 --- lib/termsupport.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index cf8f08741..145982705 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -150,8 +150,11 @@ function omz_termsupport_cwd { URL_HOST="$(omz_urlencode -P $HOST)" || return 1 URL_PATH="$(omz_urlencode -P $PWD)" || return 1 + # Konsole errors if the HOST is provided + [[ -z "$KONSOLE_VERSION" ]] || URL_HOST="" + # common control sequence (OSC 7) to set current host and path - printf "\e]7;%s\a" "file://${URL_HOST}${URL_PATH}" + printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}" } # Use a precmd hook instead of a chpwd hook to avoid contaminating output -- cgit v1.2.3-70-g09d2 From cb8b677488c7a20278917af58dfccd72cd40e1b1 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Sun, 11 Jun 2023 17:02:48 +0200 Subject: fix(termsupport): don't report current working directory in SSH sessions (#11703) --- lib/termsupport.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 145982705..6d969503d 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -121,8 +121,8 @@ fi # # As of May 2021 mlterm, PuTTY, rxvt, screen, termux & xterm simply ignore the unknown OSC. -# Don't define the function if we're inside Emacs -if [[ -n "$INSIDE_EMACS" ]]; then +# Don't define the function if we're inside Emacs or in an SSH session (#11696) +if [[ -n "$INSIDE_EMACS" || -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then return fi -- cgit v1.2.3-70-g09d2 From ccce2e1cfdf5b9680f691a402e288d9cf6ce272a Mon Sep 17 00:00:00 2001 From: James Cuzella Date: Thu, 31 Aug 2023 15:35:33 -0600 Subject: fix(termsupport): match all `foot`-like terminfo (#11868) --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 6d969503d..a800e651f 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot|contour*) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*|foot*|contour*) print -Pn "\e]2;${2:q}\a" # set window name print -Pn "\e]1;${1:q}\a" # set tab name ;; -- cgit v1.2.3-70-g09d2 From 8428442ff0e0114fab32b90443911b11a4b7f5df Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 19 Oct 2023 23:24:55 +0200 Subject: fix(termsupport): add workaround for directory tracking issues in Konsole Fixes #11683 Related: 50c6786 --- lib/termsupport.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/termsupport.zsh') diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index a800e651f..d170ffcbf 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -151,7 +151,7 @@ function omz_termsupport_cwd { URL_PATH="$(omz_urlencode -P $PWD)" || return 1 # Konsole errors if the HOST is provided - [[ -z "$KONSOLE_VERSION" ]] || URL_HOST="" + [[ -z "$KONSOLE_PROFILE_NAME" && -z "$KONSOLE_DBUS_SESSION" ]] || URL_HOST="" # common control sequence (OSC 7) to set current host and path printf "\e]7;file://%s%s\e\\" "${URL_HOST}" "${URL_PATH}" -- cgit v1.2.3-70-g09d2