Using pushd and popd with tcsh
Aside from FreeBSD induced inertia, the other reason why I stick with tcsh as my primary *nix shell are the glorious
popd stack commands.
I love stacks, they’re one of my all time favourite computer science concepts. They also remind me of hot pancakes with syrup even if they were really named for plates in diners. I’m mad about pancakes and I’m mad about stacks, sometimes even using the latter in situations where they’re not necessary or advised because they’re fun. You probably didn’t need or want to know any of this. Pancakes.
My point, and I do have one
popd commands simply allow you to push and pop directories onto a stack. If you’re as into stacks as me you can probably already start to think of all the cool things you can do with this in a shell setting and in scripts.
In a practical example, I use pushd as a drop in replacement for the venerable
cd command. I still enter
cd, but I have
pushd aliased to it in my
With it used in this way, each time I change to a different directory it gets added to the stack. This means, if if need to switch between two folders that would be tedious to rewrite each time, I can simply pop each off the stack using
popd and appear back where I was. It also has a huge history, so you can go back to a ton of different folders.
It doesn’t sound like much, but it’s probably done more to improve both my sanity and productivity than anything else in a long while. Its such a more elegant solution than using the up arrow cursor to search my command history for the cd command I used before.
Some useful .[t]cshrc arguments
If you intend to use pushd and popd in this way, I’ve found these settings in my
.cshrc if used with tcsh) make them more useful:
## Use pushd as a drop in cd replacement alias cd 'pushd' ## Return to ~/ when given no arguments, like cd set pushdtohome ## Don't print each directory added to stack ## I have the working dir shown in my prompt set pushdsilent