Linux: How to set default directory of terminal emulators?

12

1

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.

Joernsn

Posted 2011-05-02T15:49:48.883

Reputation: 645

you could try dirs -v to find out whether the last entry comes from some pushd after $HOME in some way. Just a thought. – Alain Pannetier – 2011-05-02T16:15:48.860

Answers

5

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.)

peth

Posted 2011-05-02T15:49:48.883

Reputation: 7 990

100% Correct! Thanks! I fixed it by using compiz' keyboard shortcuts instead. Very good suggestions. (The run application dialog actually behaves as it should in ubuntu natty) – Joernsn – 2011-05-16T06:33:24.947

2

I solved my problem adding a cd command at the end of my ~/.bashrc

...
cd /your_desired_path

After that, everytime you invoke the console that uses .bashrc will be prompting at your desired path.

Sergio Abreu

Posted 2011-05-02T15:49:48.883

Reputation: 121

1

You could try to put cd at the end of your ~/.zshrc.

cYrus

Posted 2011-05-02T15:49:48.883

Reputation: 18 102

Zsh is my default shell. Wouldn't this screw up scripts expecting cwd to be something else?? – Joernsn – 2011-05-16T06:33:07.430

1Scripts expect to be in the home folder at startup. – cYrus – 2011-05-16T11:16:31.293

1

A couple of things to check:

  1. Your home directory is set properly (cd ~ takes you home ok)
  2. The partition that contains your home directory is mounted and usable at the time GDM logs you in.

I had a similar problem using ZFS and having my home on a ZFS pool. ZFS wasn't starting before GDM so when it logged me in my home dir wasn't there. A few seconds later it was there though, so I could cd to it.

Majenko

Posted 2011-05-02T15:49:48.883

Reputation: 29 007

Good suggestions! 1: If i login outside X, everything works, so it seems that $HOME at least is correct there. "echo $HOME" is also correct in the terminal emulators. 2: I've tried restarting GDM after making sure everything's mounted, without luck :( – Joernsn – 2011-05-04T08:41:51.330