Adding pushd invocation to a cd command.

A coworker of mine recently introduced me to the pushd and popd commands in Unix. It's nice to be able to push a location onto a stack, and pop it off later to jump back. It almost gives you a web browser-like history or back button for command line navigation. Almost.

Where the usability starts to bend is the requirement that one needs know, ahead of time, that one will want to jump back to the current location at some point in the future. Ideally, the push of the current directory would be implicit as one moves around the filesystem. So rather than invoke popd . before every cd, I did a little shell hack and alias'ed cd

Here's what the line in my bash_profile looks like:


.bash_profile
alias cd="pushd . > /dev/null; cd"

. . . now any time I want to go back to where I've been, my directory history is stored in a stack, accessible by popd invocations.