Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH 2/2] termquery: specify $HOST in OSC7 working directory report
- X-seq: zsh-workers 54155
- From: Johannes Altmanninger <aclopte@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Cc: Johannes Altmanninger <aclopte@xxxxxxxxx>
- Subject: [PATCH 2/2] termquery: specify $HOST in OSC7 working directory report
- Date: Fri, 9 Jan 2026 12:24:39 +0100
- Archived-at: <https://zsh.org/workers/54155>
- In-reply-to: <20260109112450.2279351-1-aclopte@gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20260109112450.2279351-1-aclopte@gmail.com>
If I do
client$ cd ~
client$ ssh -t server zsh
server% cd /tmp
and then open a new terminal (using ctrl-shift-n or ctrl-shift-t),
I expect the terminal program to be started in ~, not in /tmp.
For this reason, terminals ignore the OSC 7 notification whose hostname
doesn't match the terminal's host system's.
See the discussion in
https://gitlab.freedesktop.org/terminal-wg/specifications/-/issues/20
and, as an example https://codeberg.org/dnkl/foot, commit 7466e87a
(osc: ignore OSC 7 when hostname doesn't match our own hostname,
2020-04-03) .
Support this by reporting $HOST instead of localhost.
URL-escape $HOST; this might be especially useful because this variable
can be arbitrarily changed by the user.
Also, if the user injects path components into the hostname
("HOST=a/b/c"), don't report anything, to avoid reporting garbage.
For consistency, do the same if HOST is missing ("unset HOST").
Alternatively, we could handle these cases by sending "localhost"
or an empty hostname component. No strong opinion here.
---
Src/Zle/termquery.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/Src/Zle/termquery.c b/Src/Zle/termquery.c
index 731589722..353acf0f2 100644
--- a/Src/Zle/termquery.c
+++ b/Src/Zle/termquery.c
@@ -777,11 +777,16 @@ write_urlencoded(const char *path_components)
void
notify_pwd(void)
{
+ const char *hostnam;
+
if (!extension_enabled("integration", "pwd", 11, 1))
return;
- /* only "localhost" seems to be much use here as the host */
- write_loop(SHTTY, "\033]7;file://localhost", 20);
+ if ((hostnam = getsparam("HOST")) == NULL || strchr(hostnam, '/') != NULL)
+ return;
+
+ write_loop(SHTTY, "\033]7;file://", 11);
+ write_urlencoded(hostnam);
write_urlencoded(pwd);
write_loop(SHTTY, "\033\\", 2);
}
--
2.51.0.167.g6ad8021821.dirty
Messages sorted by:
Reverse Date,
Date,
Thread,
Author