Skip to content

Instantly share code, notes, and snippets.

@rogerleite
Created December 23, 2009 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerleite/262496 to your computer and use it in GitHub Desktop.
Save rogerleite/262496 to your computer and use it in GitHub Desktop.
Shows git branch at prompt
#On Ubuntu, put this in the end of ~/.bashrc file
# Displays the current git branch name and the dirty state in your Bash shell
# prompt. Add a line like this to your ~/.bashrc file:
#
# . ~/path/to/gist/bash-git-prompt
#
# To use this, you must enable "enable programmable completion features".
# Look at your ~/.bashrc for something like:
#
# if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
# fi
#
# Otherwise, you will get an error for __git_ps1 not being found.
function __repo_branch ()
{
__git_ps1
}
function __repo_dirty ()
{
# Search for .git-prompt-disable file in parent directories
dir=`pwd`
while [ `dirname "$dir"` != "$dir" ] ; do
if [ -f "$dir/.git-prompt-disable" ] ; then perl -e 'print "? "' ; return ; fi
dir=`dirname "$dir"`
done
git status 2>&1 | grep "Not a git repository" > /dev/null && return
git status 2>/dev/null | grep "working directory clean" >/dev/null || perl -e 'print "* "'
}
#PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;33m\]$(__repo_branch)\[\033[01;31m\]$(__repo_dirty)\[\033[00m\]\$ '
PS1=':\[\033[01;34m\]\w\[\033[00m\]\[\033[01;33m\]$(__repo_branch)\[\033[01;31m\]$(__repo_dirty)\[\033[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment