As I was configuring my new system (using dotfiles configuration app I wrote for this purpose: stowage), I was exploring the current options for minimalist terminal emulators, and I realized a common pattern I wanted was for new terminals to pop up in the same working directory that I was using. Now, more feature-filled (and resource-hungry) terminal emulators often provide a Ctrl+Shift+N short-cut that will open a new window in the same working directory, but I wanted that feature to be universal.

So, I realized I could do this with a little bash profile hackery!

Here's the snippet I wrote in my bash profile:

LAST_PWD_PATH="~/.bash_last_pwd"

function cd() {  
    builtin cd "[email protected]"
    echo `pwd` > "$LAST_PWD_PATH"
}

if [ -f "$LAST_PWD_PATH" ]; then  
    builtin cd `cat $LAST_PWD_PATH`
fi  

This overrides the built-in cd command to remember the location that you are change to. Then, if such a file exists, attempts to start every new bash session by cding to that directory.

Hope it's useful!