Whenever a new tab is opened in urxvt, the cwd(current working directory) is the default directory set in bashrc.
How to make the new tab to be opened at the cwd of the current tab?
First, you could override the cd
builtin with a function that stores the current directory every time you change a directory.
cd() {
command cd $@
pwd > ~/.curdir
}
Then, you could change to this last known directory in every new shell you open:
command cd `cat ~/.curdir`
If you place both these snippets in your ~/.bashrc
, every new shell you open with have the overridden cd
command and will try to change to the last known directory:
#!/bin/bash
cd() {
command cd $@
pwd > ~/.curdir
}
command cd cat ~/.curdir
Note that I used the command
builtin to gain access to the original cd
command instead of the function named cd()
. Also note that doing this will probably have unintended side effects, especially when you have multiple shells open at the same time (which is kind of the whole point of using urxvt
tabs).
/proc/PID/cwd
maybe, then chdir to it in the main process context, then let the new-tab routine to run, then chdir back in the new-tab post-event hook (if any). – bandie Dec 04 '19 at 13:01.bashrc
to open every new shell in the last visited directory. – Jaap Joris Vens May 26 '20 at 01:07