Created
April 2, 2014 01:58
-
-
Save omwah/9926719 to your computer and use it in GitHub Desktop.
Git or Mecurial Info on Bash Prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Colors to use for prompts | |
DARK_GREY="\e[30;1m" | |
LIGHT_BLUE="\e[34;1m" | |
RESET_COLORS="\e[0m" | |
# Use git completion only if git is available on system | |
if [ -f ~/.git-completion.bash ] && [ -f `which git` ]; then | |
source ~/.git-completion.bash | |
# Include git info in prompt | |
export GIT_PROMPT='$(__git_ps1 "\[${DARK_GREY}\](\[${LIGHT_BLUE}\]%s\[${DARK_GREY}\])")' | |
fi | |
# Include Mecurial prompt if available | |
if [ ! -z $(which hg 2>/dev/null) ]; then | |
hg prompt --help 2>/dev/null >/dev/null | |
if [ $? -eq 0 ]; then | |
__hg_ps1() { | |
hg prompt $(printf "$1") 2> /dev/null | |
} | |
export HG_PROMPT='$(__hg_ps1 "\[${DARK_GREY}\](\[${LIGHT_BLUE}\]{branch}\[${DARK_GREY}\])[\[${LIGHT_BLUE}\]{status}\[${DARK_GREY}\]]")' 2> /dev/null | |
fi | |
fi | |
# Set up prompt including Git and Hg prompt components if available | |
# Use \[ \] around colors or cursor gets screwy | |
export PS1="\n\[${DARK_GREY}\](\[${LIGHT_BLUE}\]\u@\h\[${DARK_GREY}\])-(\[${LIGHT_BLUE}\]\w\[${DARK_GREY}\])\n\[${RESET_COLORS}\]${GIT_PROMPT}${HG_PROMPT}\[${DARK_GREY}\](\[${LIGHT_BLUE}\]! \!\[${DARK_GREY}\])-> \[${RESET_COLORS}\]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment