If I have changed directory in gnome-terminal away from $HOME, to i.e. $HOME/foo, then create a new tab or window, this new tab or window will have $HOME/foo as the current working directory instead of $HOME. This is new and alien to me and I prefer the old, standard behaviour of all new terminal instances being in $HOME.

I would like to acheive this without modifying my user's .profile or .bashrc (with a cd line or whatever). I am running gnome-terminal 3.18.3 on Ubuntu 16.04.

  • I was about to post the proper way of doing this (avoid emitting OSC 7 from PROMPT_COMMAND)... but then it occurred to me that Ubuntu has a patch that would stop this from working :P – egmont May 3 '17 at 14:05

I get it work by setting a custome command in profile settings, command tab.

From top menu: Edit -> Profile Preference.

Then command tab, check the Run custom command instead of my shell and set /bin/bash as your custom command.

To run the default shell instead of bash use:

/bin/sh -c '`/usr/bin/getent passwd $USER | cut -d: -f7`'

instead /bin/bash as your custom command.

enter image description here

I'm not sure what is the cause of problem, However I thing each time you create a new tab gnome-terminal forks your current instance, so it's going to inherit your old tab's working directory, but when you set a custom command it's going to create a new instance each time.

Thats only what I think is happening here.

  • This works. Although it means gnome-terminal no longer respects the user shell setting from /etc/passwd so it will be confusing if you decide to change shell (to fish, zsh or something) with chsh. I don't understand why it works though. My shell is already /bin/bash. – sapht May 2 '17 at 16:02
  • @sapht Updated the answer again, maybe gives you a clue this time ;) – Ravexina May 2 '17 at 16:46
  • Clever, but why does it help? There must be some init script that is not being sourced by gnome-terminal when an explicit shell is chosen, right? If the behaviour is hardcoded I'm filing a bug. – sapht May 2 '17 at 17:31
  • I don't think that it's a bug, I'm not using gnome, however I looked around gconf-editor to find anything about gnome-terminal but no luck. As I remember my terminals always behaved this way ... so it's nothing new to me; Also I like it this way better. – Ravexina May 2 '17 at 18:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.