Skip to content

Instantly share code, notes, and snippets.

@terrettaz
Created November 9, 2017 10:16
Show Gist options
  • Save terrettaz/473ef73d49a6bec74a1a6d6f6550e802 to your computer and use it in GitHub Desktop.
Save terrettaz/473ef73d49a6bec74a1a6d6f6550e802 to your computer and use it in GitHub Desktop.
Gist than display fast Mercurial info
# Version 1.1
__get_hg_dir() {
local d=`readlink -f "$1"`
if [ -d "$d/.hg" ]; then
echo "$d/.hg"
return 0
elif [ "$d" == "/" ]; then
echo ""
return 1
else
__get_hg_dir "$(dirname "$d")"
return $?
fi
}
__parse_hg_dirty() {
return 0 # COMMENT THIS LINE FOR DIRTY FLAG
[[ $( hg status 2> /dev/null ) != "" ]] && echo "⚡"
}
__parse_hg_branch() {
branch=$( cat "$1/branch" 2> /dev/null | sed -e 's/\(.*\)/\1/' )
[[ $branch != 'default' ]] && echo "$branch"
}
__diplay_hg_branch() {
hg_dir=$(__get_hg_dir .)
if [ $? -eq 0 ]; then
echo "[$(__parse_hg_branch "$hg_dir")$(__parse_hg_dirty)]"
fi
}
export PS1='\[\033[01;33m\]me \[\033[01;34m\]\W \[\033[01;90m\]$(__diplay_hg_branch)\[\033[01;37m\]\$ \[\033[00m\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment