7

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?

ma08
  • 855
  • 1
    to do this, one should tell rxvt about the cwd of the shell running in it somehow. i imagine an rxvt plugin hooking up to new-tab event (if there is such), looking into the cwd of current tab's child process (if it's exposed to the plugin api) in /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
  • 1
    You could twiddle with your .bashrc to open every new shell in the last visited directory. – Jaap Joris Vens May 26 '20 at 01:07
  • @hedgie How would we do that? – PascalVKooten Nov 18 '20 at 15:05

1 Answers1

1

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