j (or z) and gr (git root) For Command Line Awesomeness

Tuesday, October 25th, 2011 @ 1:18 pm | filed under: Best Practices, Tools

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):

8.93693 /Users/aaron/Development/mootools-development
17.5369 /Users/aaron/Development/foo
36.132 /Users/aaron/Development/bar
36.6632 /Users/aaron/Development/i/like/cookies
52 /Users/aaron/Development/what/do/we/have/here
97.5176 /Users/aaron/Development
270.192 /Users/aaron/Development/clientcide/Source/Interface
483.024 /Users/aaron/Development/clientcide/Source

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.


No TweetBacks yet. (Be the first to Tweet this post)

One Response to “j (or z) and gr (git root) For Command Line Awesomeness”

  1. Matt Mueller Says:

    Really useful, thanks a lot!