Created
December 23, 2009 12:49
-
-
Save rogerleite/262496 to your computer and use it in GitHub Desktop.
Shows git branch at prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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