Simple bash function to include hg information in PS1 variable in bash shell. (Gist)
Code:
#!/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