aliasing cd to pushd - is it a good idea?
Personally, I have these in my bashrc and use them all the time:
pushd()
{
if [ $# -eq 0 ]; then
DIR="${HOME}"
else
DIR="$1"
fi
builtin pushd "${DIR}" > /dev/null
echo -n "DIRSTACK: "
dirs
}
pushd_builtin()
{
builtin pushd > /dev/null
echo -n "DIRSTACK: "
dirs
}
popd()
{
builtin popd > /dev/null
echo -n "DIRSTACK: "
dirs
}
alias cd='pushd'
alias back='popd'
alias flip='pushd_builtin'
You can then navigate around on the command-line a bit like a browser. cd
changes the directory. back
goes to the previous directory that you cd
ed from. And flip
will move between the current and previous directories without popping them from the directory stack. Overall, it works great.
The only real problem that I'm aware of is the fact that it's then a set of commands that I'm completely used to but don't exist on anyone else's machine. So, if I have to use someone else's machine, it can be a bit frustrating. If you're used to just using pushd
and popd
directly, you don't have that problem. And while if you just alias cd
put not popd
, you won't have the issue of back
not existing, you'll still have the problem that cd
doesn't do quite what you expect on other machines.
I would note, however, that your particular implementation of cd
doesn't quite work like cd
in that the normal cd
by itself will go to your home directory, but yours doesn't. The version that I have here doesn't have that problem. Mine also appends DIRSTACK
onto the front of the dirs
print out, but that's more a matter of personal taste more than anything.
So, as I said, I use these aliases all the time and have no problem with them. It's just that it can be a bit frustrating to have to use another machine and then find them not there (which shouldn't be surprising, but they're one of those things that you use so often that you don't think about them, so having them not work like you're used to can still be surprising).
This isn't a direct answer to the question, but I fell in love with the directory history window in 4DOS. So much so that I wrote my own version for Linux (and Cygwin). I've never gotten around to making it an easy-to-install utility, but if you know your way around a Bash prompt, it shouldn't be that hard to get running. Your question inspired me to put it into a Git repo and upload it to GitHub: dirhistory.
Basically, it's a daemon that collects directory changes from all your shells, and a Cdk program that displays the history and lets you pick any directory to switch to (so you're not limited to a stack). I find it really useful, and have it bound to Ctrl-PageUp, just like 4DOS did. (I even patched PuTTY so it would send Ctrl-PageUp to Bash.)