Skip to content

Instantly share code, notes, and snippets.

@finwe
Forked from dundee/.bashrc
Created December 4, 2012 15:36
Show Gist options
  • Save finwe/4205225 to your computer and use it in GitHub Desktop.
Save finwe/4205225 to your computer and use it in GitHub Desktop.
Shows current git branch&status on command prompt
#GIT bash by HABR (modified by Dundee & Finwe)
export PSORIG="$PS1"
function gitbranch() {
branch="$(git branch 2>/dev/null | grep '*' | cut -d" " -f2-)"
dirty="$(git status -s 2>/dev/null)"
if [ -n "$dirty" ] ; then
color="1;33m"
else
color="0;33m"
fi
if [ -n "$branch" ] ; then
export PS1=$PSORIG$(echo -en "\[\033[$color\]$branch\[\033[0;33m\] > \[\033[00m\]")
else
export PS1="$PSORIG"
fi
}
PROMPT_COMMAND="gitbranch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment