GNOME Bugzilla – Bug 709055
Hostname part of cwd (OSC 7) is ignored
Last modified: 2021-06-10 20:34:54 UTC
As per bug 675987 comment 9 (following the link there): "You should also include the hostname so Terminal can determine whether it's a local directory; Terminal will avoid using it as the current working directory if it's from a different host." vte.sh puts the hostname in the URI but g-t doesn't check it against the actual hostname. This means that you ssh to a remote host, change to /etc there and open a new tab, you'll find yourself in localhost's /etc. I think that in accordance with the quoted text above (I can't check Mac Terminal's actual behavior) it shouldn't be like this.
You may say that vte.sh tests for VTE_VERSION which is not forwarded by ssh. The problem with this is that as far as I understand, the goal is to make this a standard feature across varios terminals and applications, rather than a hack for bash/zsh and vte only. Mac Terminal allegedly supports this feature, and hopefully some others (e.g. konsole) will follow too. It's reasonable for file managers and file viewers to set the directory or filename. It's not reasonable to duplicate checking for VTE_VERSION in all of them, especially since this feature shouldn't be VTE-specific. (E.g. I've filed a ticket to midnight commander: https://www.midnight-commander.org/ticket/3088) The proper solution I think is to check for the hostname (and be a little bit relaxed: accept either the short hostname or the fqdn or the empty string) and ignore the cwd if it doesn't match. Anything that goes to vte.sh is a partial hack that only considers vte but no other terminal emulators, and only considers bash/zsh but no other applications. Hence it's a good start to make it work for the typical use case, but not the right place for such workarounds.
If the check is done by g-t when opening a new tab, it has the drawback that sshing to a remote host (if that host also sets the working directory) overwrites the current directory with an "invalid" one, and hence opening the new tab would occur in your home dir. Probably it's a better approach if vte refuses to set the working directory to anything that doesn't belong to the local host. This way when you ssh, your local directory is remembered and the new tab is opened there. I'd probably prefer this behavior. In this case the bugreport belongs to vte rather than g-t. Since the feature is a copy of Mac Terminal's, I think the best bet is to follow their exact behavior. Unfortunately I don't have access to Mac so I cannot test it.
See also bug 767313.
See also https://github.com/jwilm/alacritty/pull/2937#issuecomment-557334660 (first screenshot).
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gnome-terminal/-/issues/7368.