ohmyzsh/lib/mercurial.zsh
Michele Bologna 194c5b1ca3 Added mercurial library
The added library parses output of the hg (mercurial) command, and outputs
the same variables (which should be customized by theme) in your prompt.
I added an example of these variables to michelebologna theme.

This patch should uniform all the behaviour of all themes regarding mercurial.
In fact, some themes implement their own hg parsing *inside* the theme.
This should be better implemented in a library, as happens with git library.
2015-09-27 10:41:02 +02:00

32 lines
976 B
Bash

# Michele Bologna
#
# Implements a hg_prompt_info function that inspect the current mercurial repo
# (if any) and then outputs the status of the repo, in a similar way with
# git.zsh library.
#
# themes should customize:
# * ZSH_THEME_HG_PROMPT_UNTRACKED - symbol to show in prompt if untracked
# files are present in the mercurial repo
# * ZSH_THEME_HG_PROMPT_ADDED - symbol to show in prompt if added files are
# present in the mercurial repo
# * ZSH_THEME_HG_PROMPT_MODIFIED - symbol to show in prompt if modified files
# are present in the mercurial repo
hg_prompt_info()
{
local STATUS=""
if $(hg id >/dev/null 2>&1); then
local BRANCH=$(hg branch 2>/dev/null)
if `hg status | grep -q "^\?"`; then
STATUS="$ZSH_THEME_HG_PROMPT_UNTRACKED"
fi
if `hg status | grep -q "^[A]"`; then
STATUS="$ZSH_THEME_HG_PROMPT_ADDED$STATUS"
fi
if `hg status | grep -q "^[M]"`; then
STATUS="$ZSH_THEME_HG_PROMPT_MODIFIED$STATUS"
fi
echo "$BRANCH$STATUS"
fi
}