I suspect there is no truly good answer to this. gnome-terminal
finds bash
's current working directory by inspecting /proc/<pid>/cwd
, which has the symlinks expanded (probably for security reasons, if nothing else). I don't know of another way for one process to find another process's working directory.
As a workaround, there are some bash tricks you could try, but see the WARNING below! In .bashrc:
...
PROMPT_COMMAND='pwd >~/.bashlocal_saved_dir'
...
[ -n "$PS1" -a -f ~/.bashlocal_saved_dir ] && cd `cat ~/.bashlocal_saved_dir`
# end of .bashrc
This will do two things. First, every time bash displays the prompt, it will first write its current working directory into the file .bashlocal_saved_dir
in your home directory. Second, when bash starts interactively (as opposed to running a script), it will change to the directory stored in that same file. This means that when you start a new interactive bash, it will start in the same dir as the bash that last displayed its prompt. Note that you can hit Enter to cause a bash to redisplay its prompt, thus making it the last. :)
WARNING: This is a hack, and I have only tried it up to the point that I know it works. Think bubble gum and shoestrings. It may have surprising effects, and will certainly not work as cleanly as gnome-terminal
's approach. In particular, if you're running a lot of tabs at once, all doing background tasks, you may very well end up in the "wrong" directory when opening a new tab.
I cannot reproduce the behavior you describe with Ubuntu 10.04 and all default settings for gnome-terminal and bash. The problem may be a setting in your
.bashrc
; try moving it temporarily out of the way to check. If the problem persists, add more information, at least the versions ofgnome-terminal
andbash
, and a detailed list of steps to reproduce this behavior. – Gilles 'SO- stop being evil' – 2010-08-31T21:15:33.0231I can reproduce it. By "directory that includes symlinks" he means "working directory whose path includes symlinks". Under
gnome-terminal
2.30.2 andbash
4.1.5:mkdir -p foo/bar/baz; ln -s foo/bar/baz link; cd link
-- then create new tab -- thenpwd
. It will report "foo/bar/baz" rather than "link". – Jander – 2010-12-05T21:30:41.437@Jander, thanks, I'll edit to include your clarification. – Ian Mackinnon – 2010-12-05T22:30:11.777