Ubuntu – Linux: How to set default directory of terminal emulators

gnomegnome-terminalterminalUbuntuurxvt

After upgrading to Ubuntu 11.04, my terminals (gnome-terminal and urxvt) start in "/" instead of "~"

What can cause this behavior?

I imagine that the working directory of Gnome or X is set to "/", or something like that, but I have no idea on where to start debugging this.

I use zsh, config can be included.

Best Answer

I assume you see this behavior when opening the terms with custom keyboard shortcuts while they start in the right directory if opened via the menu or the Run Application dialog.

Curiously programs you define under the Custom Shortcuts section of the Gnome Keyboard Shortcuts dialog don't seem to inherit the session working directory. Knowing nothing about the reasons, I suspect this is a bug.

Workarounds:

  • Use the Run a terminal shortcut in the Desktop section and set your preferred terminal emulator under System => Preferences => Preferred Applications => System => Terminal Emulator,

  • Set the keyboard shortcut to a wrapper script, e.g.

    #!/bin/sh
    exec rxvt -cd $HOME
    
  • Define the shortcut to include setting the working directory, e.g.:

    gnome-terminal --working-directory=$HOME
    

    or

    rxvt -cd /path/to/home
    

    (The latter doesn't work with $HOME for me; I had to give the absolute path.)

Related Question