Hacker News new | ask | show | jobs
Linux terminal trick: Hack the CD command to remember where you've been (redhat.com)
5 points by jhibbets 2105 days ago
1 comments

This is a neat idea, but I don't do it because most of the time I don't want to have to traverse every previous dir. If you use `cd -` then you'll go back to the previous dir anyway, which covers most cases. Beyond that, it's just better to get in the habit of using pushd so that you can jump back to exactly where you want :-) It's totally worth it.

One thing that annoys me is that popd consumes the top of the stack, which I something don't want. I put this in my bashrc some years ago which basically executes a popd but doesn't pop the stack:

    alias peekd='cd "$(dirs -l -p | sed -n '\''2{p;q}'\'')"'