Skip to content

Instantly share code, notes, and snippets.

@drazenzen
Last active December 18, 2015 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drazenzen/88d24ee9fab819cd6ee8 to your computer and use it in GitHub Desktop.
Save drazenzen/88d24ee9fab819cd6ee8 to your computer and use it in GitHub Desktop.
hg PS1 bash shell helper
#!/bin/bash
#
# Ref: http://unix.stackexchange.com/questions/66581
# For getting both exit status and output from command
#
# __hg_ps1 function shows hg branch and minified hg status when working directory is in a mercurial repo.
#
__hg_ps1() {
local INFO
INFO=$(hg branch 2> /dev/null)
if [ $? -eq 0 ]; then
echo -e "[$INFO $(hg status | cut -b 1 | uniq | sort | tr -d '\n')]"
fi
}
# PS1 example
export PS1='$(__hg_ps1)'$PS1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment