Comment 6 for bug 1609342

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

gnome-terminal 3.36, which is included in Ubuntu 20.04, added a config option Preferences -> <profile> -> Command -> Preserve working directory.

Older versions preserved the directory only when launching a shell, not when launching a custom command. This behavior was frowned upon by some folks, understandably.

The change is at https://gitlab.gnome.org/GNOME/gnome-terminal/-/commit/79b2291 , the two bugtracker entries are linked from the commit message.

Now, in order for this to work, two more things have to happen: Whichever application (presumably your shell) is running in the source window has to set the desired value, and whichever application is starting up in the new window has to respect it (not intentionally override it).

For setting: vte-2.91 is intended to do that, see its __vte_osc7() method. Now there's a chance that some fragment in your shell profile overrides it. To debug I recommend to manually issue the given escape sequence and then not give back control to the shell, not to give it a chance to override from PS1 or PROMPT_COMMAND or so:

  printf "\e]7;file:/etc\e\\" ; sleep 1000

A newly opened tab should be in /etc now. If this fixes the problem then try it without the sleep. If that still fixes then your shell just doesn't emit it. If removing the sleep breaks it again then there's something in your prompt overriding the value.

To debug the other side: Set up a custom command of "sleep 2000", open a new window, from another terminal locate the pid of this sleep, and check its working directory at /proc/<pid>/cwd. If this is set correctly, yet it doesn't work your shell or custom command, then it's that command intentionally switching to some other directory.