Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Forked from kevinohara80/.bash_profile
Last active December 11, 2015 06:09
Show Gist options
  • Save AdamMagaluk/4557554 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/4557554 to your computer and use it in GitHub Desktop.
Forked from Kevin O'Hara, but added mercurial fall back when git repo does not exist.
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_hg_branch() {
echo -ne "[`hg branch 2> /dev/null`"; if [ "`hg status 2> /dev/null`" ]; then echo "*]"; else echo "]"; fi
}
function parse_git_branch() {
B=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"`
if [ $B ]; then echo $B; else parse_hg_branch; fi
}
# ANSI COLORS
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
CYAN="\[\033[0;36m\]"
BLUE="\[\033[0;34m\]"
LGRAY="\[\033[0;37m\]"
DGRAY="\[\033[1;30m\]"
RESET="\[\033[0m\]"
# BASH PROMPT
export PS1="$DGRAY\w$BLUE \$(parse_git_branch)\n$GREEN\[\e[32m\]λ:$RESET "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment