Skip to content

Instantly share code, notes, and snippets.

@rajraj
Forked from henrik/.bashrc
Created March 29, 2012 07:25
Show Gist options
  • Save rajraj/2234508 to your computer and use it in GitHub Desktop.
Save rajraj/2234508 to your computer and use it in GitHub Desktop.
Git branch and dirty state in Bash prompt.
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
# Edit .bash_profile
$ nano ~/.bash_profile
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
PS1='\[\033[00m\]\u@\h\[\033[0;32m\] \w \[\033[31m\]$(parse_git_branch) \[\033[00m\]$\[\033[00m\] '
# Reload .bash_profile
$ source ~/.bash_profile
# http://jblevins.org/log/git-colors
# Add colour to git
$ nano ~/.gitconfig
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold
[color "status"]
added = green
changed = red
untracked = cyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment