Skip to content

Instantly share code, notes, and snippets.

@bsag
Forked from henrik/.bashrc
Created January 15, 2009 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bsag/47541 to your computer and use it in GitHub Desktop.
Save bsag/47541 to your computer and use it in GitHub Desktop.
# 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
# bsag: I combined the best of both worlds and used the parse_git_dirty function here:
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/#comment-4166
# as well as various other mods from the forks of this gist.
function parse_git_dirty {
git diff --quiet HEAD &>/dev/null
[[ $? == 1 ]] && echo "*"
}
function parse_git_branch {
ref=$(git-symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# 3 line prompt:
# >>> {bash history number} {username}
# {time} {working directory}
# [git branch and state] $
export PS1='\[\033[1;31m\]>>> \! \[\033[0;37m\]\u\[\033[0;33m\] \[\033[1;33m\] \n \[\033[0;37m\]\@ \[\033[1;33m\]$(dirs)\n [$(parse_git_branch)$(parse_git_dirty)] $\[\033[0m\] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment