j (or z) and gr (git root) For Command Line Awesomeness
Here’s a little command line utility I use the hell out of:
Basically, this script tracks the directories you cd into on the command line and builds a rank order of their locations. Here’s a chunk of mine (with some fake directory names to protect the innocent):
If I type “z Source” I’ll automatically jump to that last line because it’s the highest ranked entry that matches that string. “z interface” will take me to the line above it. “z Devel” will take me to the line above that. It’s remarkably smart; it’s very rare that I end up somewhere other than what I want to be, even when I only use one or two characters from the location I’m after (“z clientcide” takes me to clientcide/Source, which may not be what I wanted).
Note: Originally it was called “j” (https://github.com/rupa/j) and I got so used to using that alias that I have “j” aliased to this script. z is the more recent implementation.
Oh, and here’s another one:
alias gr='[ ! -z `git rev-parse --show-cdup` ] && cd `git rev-parse --show-cdup || pwd`'
That command (gr) will take me to the root of any git repo I’m in.