Skip to content

Possible failure to recognize file://$HOSTNAME/ prefix in OSC 7 cwd notification #1330

@krobelus

Description

@krobelus

(EDIT: the response landed in my spam folder) I tried sending this to the cygwin mailing list on August 2 but it doesn't seem to have arrived - it doesn't show up in the archives.
Here's the same patch.
The problem (if it exists) might be easy to reproduce: change to some directory, send the OSC 7 notification with the attached printf command,
and then open a new Tab; this patch might make the new tab use the right directory.
I haven't been able to test this unfortunately but I hope that we can figure this out soon-ish because otherwise lots of users might run into this problem (because fish shell, which sends such OSC 7 notifications, is about to be released on msys2)

From 70aa5518897b13f308165021f911d3629e721668 Mon Sep 17 00:00:00 2001
From: Johannes Altmanninger <[email protected]>
Date: Sat, 2 Aug 2025 15:11:34 +0200
Subject: [PATCH] Recognize file://$HOSTNAME/ prefix in OSC 7 cwd notifications

While investigating https://github.com/fish-shell/fish-shell/issues/11676
(which looks to be an issue in VSCode's shell integration), I found a
potential problem with running this command in Bash inside mintty:

	printf '\e]7\;file://%s%s\a' "$HOSTNAME" "$PWD"

This is an OSC 7 working directory notification, telling the terminal which
directory to use for new windows/tabs.

I noticed that mintty seems to handle only "file:///" and "file://localhost/"
URLs but not "file://$HOSTNAME/".

It's not very easy for me to confirm this; if true, we might want to use
something like the attached patch (which is completely untested).
---
 src/termout.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/termout.c b/src/termout.c
index ab55198d..7cd68910 100644
--- a/src/termout.c
+++ b/src/termout.c
@@ -4600,6 +4600,20 @@ do_cmd(void)
         s += 11;
       else if (!strncmp(s, "///", 3))
         s += 2;
+      else {
+        char host_component[UT_HOSTSIZE + strlen("///")];
+        host_component[0] = '/';
+        host_component[1] = '/';
+        if (gethostname(host_component + strlen("//"), sizeof host_component - strlen("//")) < 0) {
+          host_component[0] == 0;
+        } else {
+          char* end = host_component + strlen(host_component);
+          end[0] = '/';
+          end[1] = '\0';
+        }
+        if (!strncmp(s, host_component, strlen(host_component)))
+            s += strlen(host_component);
+      }
 
       // do not check guardpath() here or it might beep on every prompt...
 
-- 
2.50.1.194.g038143def7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions