Yevgeniy A. Viktorov

Personal Weblog

Displaying git and mercurial info in zsh prompt

Lately I was(and I still) spending more time with Mercurial and being missing a little bits in my Zsh prompt, but google rescued me quickly :) All creds to Steve Losh who seems contributed great amount of time explaining his extravagant Zsh prompt which can handle both Git and Mercurial statuses seamlessly and nicely, see his explanatory screenshot:

Screenshot: Zsh prompt Comments

If your workflow not rely on the latest additions, you don’t maintain your own fork yet or you just new to oh-my-zsh, then you can jump to Steve’s guide and also use his fork of oh-my-zsh.

In the next lines I’ll try to explain the steps to get those bit’s working with the latest(at least as of today) oh-my-zsh. I’ll also cover some installation steps which you can skip if you have oh-my-zsh already installed and know what’s going on there and here :)

Make your Fork

This might be a good idea since we going to modify one core file and add your own theme. So, go to robbyrussell/oh-my-zsh and click “Fork”

Install, oh my, Zsh?

This is a bit modified version of Manual Way installation from oh-my-zsh readme, where we using your fork instead of robbyrussel’s.

  1. Clone the repository
    git clone git://github.com/YOU-YOU-YO/oh-my-zsh.git ~/.oh-my-zsh
  2. Create a new zsh config by copying the zsh template we’ve provided.
    NOTE: If you already have a ~/.zshrc file, you should back it up. cp ~/.zshrc ~/.zshrc.orig in case you want to go back to your original settings. cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  3. Set zsh as your default shell:
    chsh -s /bin/zsh
  4. Start / restart zsh (open a new terminal is easy enough…)

Modify lib/git.zsh

See what exactly was changed here:

https://github.com/yeevgen/oh-my-zsh/commit/3d4b686750d0586007e5d11d812ef8aebc76c52a

Add your theme

Here is mine, identical to Steve’s prose theme, except battery indicator removed(I’m on desktop) and RVM prompt added:
yeevgen.zsh-theme

  • download into ~/.oh-my-zsh/themes and name as you like;
  • adjust ZSH_THEME variable, see ~/.zshrc

Done!

Restart your console and enjoy!

What next? TODO, ideas, etc.

  • look for a better way to incorporate into main stream
  • send pull request to robbyrussel/oh-my-zsh
  • buzz me :)

Thanks.

About these ads

One response to “Displaying git and mercurial info in zsh prompt

  1. ocodo (@ocodo) December 8, 2012 at 1:26 am

    I recently added a SVG version of the XTerm color chart to Wikipedia, so you can get infinite resolution color chart out of it. Wonderful for composing your awesome prompts. http://en.wikipedia.org/wiki/xterm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: