Skip to content

Instantly share code, notes, and snippets.

@vishvananda
Forked from anonymous/gist:1237339
Created September 23, 2011 13:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishvananda/1237345 to your computer and use it in GitHub Desktop.
Save vishvananda/1237345 to your computer and use it in GitHub Desktop.
function git_branch {
git branch --no-color 2> /dev/null | egrep '^\*' | sed -e 's/^* //'
}
function git_dirty {
# only tracks modifications, not unknown files needing adds
if [ -z "`git status -s | awk '{print $1}' | grep '[ADMTU]'`" ] ; then
return 1
else
return 0
fi
}
function dirty_git_prompt {
branch=`git_branch`
if [ -z "${branch}" ] ; then
return
fi
git_dirty && echo " (${branch})"
}
function clean_git_prompt {
branch=`git_branch`
if [ -z "${branch}" ] ; then
return
fi
git_dirty || echo " (${branch})"
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;31m\]$(dirty_git_prompt)\[\033[01;32m\]$(clean_git_prompt)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w $(git_branch)\$ '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment