yannk (owner)

Fork Of

gist: 31631 by henrik Git branch and dirty state ...

Forks

Revisions

gist: 52483 Download_button fork
public
Description:
[plumbing] bash prompt integrating gist
Public Clone URL: git://gist.github.com/52483.git
.bashrc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# add in your .bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# http://blog.cyberion.net/2009/01/improved-bash-prompt-for-git-usage.html
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master⚡]$ # dirty working directory
#
# I've made the following ajustements:
# - Use of plumbing, that should be faster than git status porcelain.
# - Don't show my repo as dirty if it has files unknown from the index (I always have).
# - Integrated to debian's PS1 (trivial to adapt) and uses standard __git_ps1 from bash_completion
 
# NOTE: if you notice bash weirdness, disable colors
function __git_dirty {
    local dirty RED NO_COLOR
    RED="\033[0;31m"
    NO_COLOR="\e[0m"
    dirty=$(git diff-index --cached --quiet HEAD 2>/dev/null || echo "⚡")
    if [ ! -z "$dirty" ]; then
echo "${RED}${dirty}${NO_COLOR}";
        return;
    fi
dirty=$(git diff-index --quiet HEAD 2>/dev/null || echo "⚡")
    [ -z "$dirty" ] && return
echo "${RED}${dirty}${NO_COLOR}";
}
 
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]$(__git_ps1 " [%s$(__git_dirty)]")\$ '