If I'm using gnome-terminal
in a working directory whose path includes symlinks and I open a new tab, the symlinks will be expanded to their destinations in the working directory of the new tab.
Is there any way to preserve the symlinks when opening a new tab?
Best Answer
I suspect there is no truly good answer to this.
gnome-terminal
findsbash
'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:
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.