Linux: How to set default directory of terminal emulators?

13,149

Solution 1

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

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

Solution 3

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

Solution 4

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.

Share:
13,149
Joernsn
Author by

Joernsn

Updated on September 18, 2022

Comments

  • Joernsn
    Joernsn over 1 year

    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
    Joernsn almost 13 years
    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
    Joernsn almost 13 years
    Zsh is my default shell. Wouldn't this screw up scripts expecting cwd to be something else??
  • Joernsn
    Joernsn almost 13 years
    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)
  • cYrus
    cYrus almost 13 years
    Scripts expect to be in the home folder at startup.