Skip to content

Instantly share code, notes, and snippets.

@johnnypez
Created April 24, 2013 09:02
Show Gist options
  • Save johnnypez/5450775 to your computer and use it in GitHub Desktop.
Save johnnypez/5450775 to your computer and use it in GitHub Desktop.
shows cwd / user / git branch info in bash prompt
function parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
function get_git_color() {
isred=`git status -s 2> /dev/null | egrep "^.[^? ]" | wc | awk '{print $1}'`
isorange=`git status -s 2> /dev/null | egrep "^[^? ]" | wc | awk '{print $1}'`
git_prompt_color=32
if [ $isorange -ne 0 ]
then
git_prompt_color=33
fi
if [ $isred -ne 0 ]
then
git_prompt_color=31
fi
echo "$git_prompt_color"
}
export PS1="\[\e[01;31m\]\w \u \[\e[1;\$(get_git_color)m\]\$(parse_git_branch) \[\e[01;31m\]$ \[\e[0m\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment