Gnome-terminal sets directory to HOME for ctrl-shift-n and custom shell command

Bug #1609342 reported by Zwinkau
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
gnome-terminal (Ubuntu)
Confirmed
Low
Unassigned

Bug Description

With Ubuntu 14.04 I could Ctrl-Shift-N in my gnome-terminal and another terminal window came up with the same working directory. When I upgraded to 16.04.1, the new terminal window now always uses $HOME as working directory. I want the 14.04 behavior.

This has nothing to do with sourcing /etc/profile.d/vte.sh. Fish does this correctly as I can observe directory changes in the title bar. If I uncheck the custom command box in my gnome-terminal profile, the new terminal window correctly uses the current directory. However, it uses my system default shell: bash.

For some reason gnome-terminal does not set the working directory if I use a custom command.

ProblemType: Bug
DistroRelease: Ubuntu 16.04
Package: gnome-terminal 3.18.3-1ubuntu1
ProcVersionSignature: Ubuntu 4.4.0-31.50-generic 4.4.13
Uname: Linux 4.4.0-31-generic x86_64
NonfreeKernelModules: openafs nvidia
ApportVersion: 2.20.1-0ubuntu2.1
Architecture: amd64
CurrentDesktop: Unity
Date: Wed Aug 3 12:32:22 2016
InstallationDate: Installed on 2013-02-13 (1266 days ago)
InstallationMedia: Ubuntu 12.10 "Quantal Quetzal" - Release amd64 (20121017.5)
JournalErrors:
 Error: command ['journalctl', '-b', '--priority=warning', '--lines=1000'] failed with exit code 1: Hint: You are currently not seeing messages from other users and the system.
       Users in the 'systemd-journal' group can see all messages. Pass -q to
       turn off this notice.
 No journal files were opened due to insufficient permissions.
SourcePackage: gnome-terminal
UpgradeStatus: Upgraded to xenial on 2016-08-01 (1 days ago)

Revision history for this message
Zwinkau (qznc) wrote :
tags: added: dist-upgrade regression-release
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gnome-terminal (Ubuntu):
status: New → Confirmed
Revision history for this message
Zwinkau (qznc) wrote :

For workarounds, see Stackoverflow: http://unix.stackexchange.com/q/299989/123188

Changed in gnome-terminal (Ubuntu):
importance: Undecided → Medium
importance: Medium → Low
Revision history for this message
Éric Piel (Delmic) (piel) wrote :

Still happening on Ubuntu 18.04, but in Ubuntu 20.04, gnome-terminal now has an option to keep or not the working directory.

Revision history for this message
Yury V. Zaytsev (zyv) wrote :

Hi,

So, this is affecting me on Ubuntu 20.04 - gnome-terminal no longer preserves the current working directory in bash upon opening a new window (or tab) from the context menu. Does anyone know what's going on?

The /etc/profile.d/vte-2.91.sh script is being sourced correctly, but I believe that it only has to do with the pwd in the titlebar, which is also working.

Switching to fish as proposed on StackOverflow is not an option... Any tips? :-(

All the best,
Yury

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.

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

For setting: vte-2.91.sh is intended to do that... the ".sh" extension was missing, sorry.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.