June 25, 2013

Extending oh-my-zsh with hg_prompt

If you are using oh-my-zsh framework for your zsh (if not, just look at this) then you may noticed that there is a nice out-of-box prompt for git repositories:

If you would like to do something similar with your mercurial prompt, then you will need:

1
Install hg prompt
2
Add 'mercurial' plugin to the list of your zsh plugins (~/.zshrc):
plugins=(git, mercurial)

3
Add the following after "source $ZSH/oh-my-zsh.sh":
source $ZSH/oh-my-zsh.sh

# Things to add:

function hg_prompt_info {
    hg prompt --angle-brackets "\
<%{$fg_bold[blue]%}hg:(%{$fg_bold[red]%}<branch>><:<tags|, >%{$fg_bold[blue]%})>\
%{$fg[yellow]%}<status|modified|unknown><update>\
<patches: <patches|join( → )>>%{$reset_color%}" 2>/dev/null
}

PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)$(hg_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'


3
Have a nice mercurial prompt!

2 comments:

  1. Replies
    1. You're welcome.

      Pay attention: if you have multiple heads in the repo, then last char in the prompt may be eaten by some poltergeist.

      Delete