A simple persistent DIRSTACK in bash

Here’s a simple way to use a persistent DIRSTACK in bash:

a script in your path called dhs saves your current DIRSTACK:

dirs -l -p > /home/username/.drsk/pwdirs

And another one called dh to loads a dirstack from a file in ~/.drsk/, you may like to use different different dirstacks for separate projects:

for i in `cat ~/.drsk/$1`;
do pushd $i > /dev/null 2>&1
pushd +$( expr ${#DIRSTACK[@]} – 1 ) > /dev/null 2>&1
popd > /dev/null 2>&1
echo “DIRSTACK restored from ~/.drsk/$1”
dirs -v -l

and in your ~/.bashrc you can add:

source dh pwdirs

to load the default. When you adjust your working dirstack you can call `. dhs`to save it and each new terminal you open will use the same one.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s