Skip to content

Instantly share code, notes, and snippets.

@caugner
Created September 14, 2017 20:30
Show Gist options
  • Select an option

  • Save caugner/59a3863314702de01ec07848ad0538ed to your computer and use it in GitHub Desktop.

Select an option

Save caugner/59a3863314702de01ec07848ad0538ed to your computer and use it in GitHub Desktop.
prompt_hg()
prompt_hg() {
(( $+commands[hg] )) || return
local rev status
if $(hg root 2> /dev/null); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
prompt_segment red white
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
prompt_segment yellow black
st='±'
else
# if working copy is clean
prompt_segment green black
fi
echo -n $(hg prompt "☿ {rev}@{branch}") $st
else
hgst=$(hg st -uma | cut -c -1 | sort | uniq | paste -d, -s)
st=""
rev_branch=$(hg id -nb 2>/dev/null)
if `echo "$hgst" | grep -q "[?]"`; then
prompt_segment red black
elif `echo "$hgst" | grep -q "[MA]"`; then
prompt_segment yellow black
else
prompt_segment green black
fi
echo -n "☿ $rev_branch" $st
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment