Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # 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
- #
- # Since Bash 3.1, Debian has moved the file bash_completion to the bash-completion
- # package, so: apt-get install bash-completion
- #
- # Otherwise, you will get an error for __git_ps1 not being found.
- if [ -r /etc/bash_completion.d/git ] ; then
- function __repo_branch ()
- {
- __git_ps1
- }
- function __git_prompt_enabled ()
- {
- # Search for .git-prompt-disable file in parent directories
- dir=`pwd`
- while [ `dirname "$dir"` != "$dir" ] ; do
- if [ -f "$dir/.git-prompt-enable" ] ; then return 0 ; fi
- if [ -f "$dir/.git-prompt-disable" ] ; then return 1 ; fi
- dir=`dirname "$dir"`
- done
- }
- function __repo_dirty ()
- {
- __git_prompt_enabled || ( perl -e 'print "? "' ; exit 1 ) || return
- status=`git status 2>&1`
- if [[ "$status" =~ "Not a git repository" ]] ; then return ; fi
- if [[ "$status" =~ "Changed but not updated" ]] ; then perl -e 'print "C "' ; return ; fi
- if [[ "$status" =~ "Untracked files" ]] ; then perl -e 'print "u "' ; return ; fi
- if [[ "$status" =~ "Changes to be committed" ]] ; then perl -e 'print "i "' ; return ; fi
- if [[ "$status" =~ "Your branch is ahead" ]] ; then perl -e 'print "a "' ; return ; fi
- }
- 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\]\$ '
- fi
Add Comment
Please, Sign In to add comment