Customizing zshrc prompt to have git info in Ruby

I’ve been using Gary B’s dotfiles ever since I saw his PeepCode screencast, especially like his zshrc prompt, which looks like:

bin(0min|master?) $

bin - folder name 0 min - time since last commit master - name of current branch ! - there untracked files in the repo.

Its pretty helpful since I use terminal a lot, but one problem is the speed when switching to new repos, especially ones not opened for a long time. I didn’t mind it that much, especially since I found no good alternatives, but after looking at PeepCode’s latest blog post, and seeing they used Ruby, I decided to switch. PeepCode was nice enough to include the dotfiles, so I mostly just adapted that. My prompt now, looks something like:

bin(1hr|master!)☺

Its mostly the same except the time is more descriptive. The older one showed just minutes, which after 2 days since didn’t make sense anymore. This one is a little faster than the older one and in Ruby. It also shows if branch is behind or ahead of remote in terms of commits with ↑ and ↓. I’m not very proud of the code and it is unnecessarily slow at some points, but it works and has a smiley, which I also stole from PeepCode.

I pushed them to my dotfiles repo, if you’re interested. See zshrc and ruby script.

P.S. Both the prompts use color. They’re not visible since I just copied and pasted.