Skip to content

Instantly share code, notes, and snippets.

@treehead
Forked from henrik/.bashrc
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save treehead/fb3c565474d843591949 to your computer and use it in GitHub Desktop.

Select an option

Save treehead/fb3c565474d843591949 to your computer and use it in GitHub Desktop.
# Source:
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
#
# CWD and dollar prompt on a new line with git Git branch and dirty state
# ~/dev/dir
# $ # non-git working directory
#
# ~/dev/dir
# [master]$ # clean working directory
#
# ~/dev/dir
# [master*]$ # dirty working directory
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='\n\[\e]0;\w\a\]\n\[\033[0;34m\]\w\[\033[0m\]\n\[\033[1;33m\]$(parse_git_branch)\[\033[0m\]$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment