3

I source vte.sh in my .bashrc. One thing this does is it causes Bash to echo "\033]7;file://$HOSTNAME$PWD\007" as part of PROMPT_COMMAND. This uses the escape sequence "OSC 7" to send a value like file://mylocalbox/home/kerrick to the terminal, telling it what the current hostname and directory are. When you open a new tab in GNOME Terminal, it uses the information from OSC 7 to open the terminal in the same directory as the previous tab.

I would like to configure GNOME Terminal so that if the current tab is running a SSH session, launching a new tab will SSH into the same host and change to the same directory. In other words, if the OSC 7 value is something like file://myremotebox/foo/bar, it will run exec ssh -t myremotebox 'cd /foo/bar && exec bash -l' instead of a default terminal session.

How can I configure GNOME Terminal to do this?

1 Answers1

1

It doesn't support this feature, you'd need to modify its source code. It's probably a reasonably straightforward task, if you're somewhat used to touching foreign C++ code.


Note:

While you can certainly come up with a patch that works in a significant amount of cases, there will always be cases that cannot be handled 100% reliably.

Maybe the remote username differs from the local one. The username is not part of the OSC 7 sequence, so you cannot tell what the remote username is.

Maybe the remote hostname (as the remote host calls itself) cannot be used on the local host to resolve to its address.

Maybe the site was reached via multiple ssh hops.

Maybe sshd is running on a nondefault port.

Maybe it's not ssh but old-fashioned rsh / telnet or something alike.

Probably there's more... Cases like these would hardly make such a feature eligible for mainstream inclusion, it would just break too often (especially the username mismatch is a valid concern in practice). OSC 7 gives you partial information about where you are, whereas what you'd need is how to get there.

egmont
  • 5,866
  • Do you happen to know if there is a way to ask GNOME Terminal what the last value sent via OSC 7 was? If not, I think it'd be reasonable to ask upstream to include some API for this; I will file a feature request. – Kerrick Staley Dec 31 '22 at 20:06
  • According to my memories (which might be incorrect or outdated) there's no sequence to query the value set by OSC 7. The sequences to query the window title (OSC 0, 1, 2) were removed from many terminals due to security problems, so presumably a request to add something similar for OSC 7 would be rejected. Or if you mean API as in, well, programmer-like API (e.g. running gnome-terminal with a certain command line parameter), rather than an escape sequence inside the tty line, you couldn't identify which of the multiple terminals it's handling you're referring to. – egmont Jan 01 '23 at 11:29