I’ve been using zsh has my primary shell since attending Überconf last July in Denver Colorado. For all intents and purposes it’s a superset of the venerable bash shell. I’ve also been using oh-my-zsh, which is a community driven framework for managing your zsh configuration.
Yesterday evening I refactored my prompt using Steve Losh’s My Extravagant Zsh Prompt posting as a jumping off point. The end result is a nicely colorful, informationally dense prompt. In addition to showing me what machine I’m on, it displays the current working directory, the Ruby version, and information about source control should the working directory contain either a Git, Mercurial (hg), or Subversion (svn) repository.
A picture, or screen shot, is worth a thousand words.
And here’s an annotated image that explains all the parts and pieces.
##Create an oh-my-zsh theme
I copied the Soliah theme when I started with oh-my-zsh originally. Over time I’ve completely modified it to suit my tastes. Browse through the theme offerings and find one you like. Make a copy and give it a unique name. I named mine after my domain, or zanshin.zsh-theme.
You can grab a copy of my theme file from my dotfiles repository on Github.
From left to right my prompt shows me:
The user name I’m currently logged in under
The hostname of the machine I’m currently at
The path to the current working directory
If there is a source control repository present at the working directory, git, hg, or svn, information about the state of the repository is shown next.
For Git repositories the prompt character changes to a ± and this information is shown:
The branch name
A [dirty] flag if there are tracked but not committed changes
A [untracked] flag if there are untracked changes present
For hg repositories the prompt character changes to a ☿ and the following information is shown:
The branch name
The location of the checkout relative to the tip
For svn repositories the prompt character changes to a ⚡ and the following information is shown:
The trunk, branch, or tag currently checked out
The revision number
And a [dirty] indicator if there are uncommitted changes
Zsh supports the idea of a right prompt and I’ve made use of this to show the current Ruby version. I’m using rbenv to manage my Ruby versions. The presence of a .rbenv-version file triggers changing the Ruby in effect. My right prompt queries rbenv to determine what to display.
Steve Losh’s prompt works beautifully as-is for git and hg repositories. I wanted to extend my prompt to work for subversion repositories since my employer is subversion-based. I got the bulk of my svn prompt from this Landon Fuller gist.
I stripped out some of his code, paring it down to just the bare essentials to display svn information. What his prompt script didn’t provide was a way to indicate whether or not the working directory had uncommitted changes. Using output from the bash prompt builder as an example I was able to add a test for uncommitted changes.
Here’s a copy of the complete zsh-theme I’m using.