Make better use of your bash cdpath

I just found out about this today, and it kinda blew me away.

there’s an environment variable in bash ‘CDPATH’ that checks to see what the directory names are for easy transitioning from directory to directory. Normally the cdpath variable is just .  Tab completion helps immensely with this, but this is still much faster:

to get from ~/ to ~/work/puppet/modules/my_module I’d normally type

cd ~/wo<tab>pup<tab>mod<tab>my_mod<tab>

but when I’ve added ~/work/puppet/modules to my cdpath, I just have to type

cd my_module

I added a few common directories I store my projects into to this, and viola! yay!

here’s what I did to set it up:

$ mkdir .bash
$ cd .bash
$ cat << EOF >>
> #!/bin/bash
> export CDPATH='.:~:~/git:~/git/puppet:~/git/puppet/modules'
$ chmod +x
Now you just have to add this to your startup scripts. I'd just append the following to my .bash_profile and call it a day:
$ echo 'source ~/.bash/' >>~/.bash_profile

and now:

~$ pwd
~$ cd common
~/git/puppet/modules/common (master)$ cd hieradata
~/git/puppet/hieradata (master)$ cd ~

Hope this helps someone else!