Preserving your working directory in gnome-terminal

I use gnome-terminal for most of my hacking. In fact, I use it so much, that I’ll often have multiple tabs open for a particular project. Here’s my workflow:

  1. Control+Alt+t (My shortcut to open a new gnome-terminal window.)
  2. cd ~/code/some_cool_hack/ # directory of some cool hack
  3. Control-Shift-t (Shortcut to open a new gnome-terminal tab.)
  4. Hack, hack, hack…

The problem is that the new tab that I’ve created will have a $PWD of ~, instead of keeping the $PWD of ~/code/some_cool_hack/, which is the project I’m working on!

The solution is to add:

# including this ensures that new gnome-terminal tabs keep the parent `pwd` !
if [ -e /etc/profile.d/ ]; then
    . /etc/profile.d/

to your ~/.bashrc. Now everything works perfectly!

Many thanks to Matthias Clasen and Ray Strode for figuring this one out!

One side note: this used to be the default, but for some reason it broke around Fedora 19 or 20. Maybe it had to do with my fancy prompt, but everything is working great now.

Happy Hacking,



8 thoughts on “Preserving your working directory in gnome-terminal

  1. It still does work that way for me by default. I think everything in /etc/profile.d is supposed to be sourced whenever a new terminal is opened. Perhaps something earlier (alphabetically, I guess?) is failing and causing later things not to be sourced?

    • Indeed! I’m running a heavily modified ~/.bashrc so at least now I know which bits I needed to poke again to get this working :)
      Glad to hear it works out of the box for you!

  2. This feature was removed together with background-transparency with version 3.6. Many people told the developer that this was not okay, but it was ignored.

  3. It worked for me but only for opening a new tab, not for opening a new terminal pressing Ctrl+Alt+T from the existing one.. This used to work in my previous Ubuntu..

    • Very strange. All is working for me at the moment, so if you do have issues, make sure to file a bug! I think ubuntu gets updates a little later than Fedora (Fedora bleeds more) so perhaps the issue that hit me a while back in Fedora, has now hit ubuntu users?

      Good luck, and if you have any information if this is related to a specific developer commit, or just to people who hack their bashrc, let me know!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s