Skip to content

Instantly share code, notes, and snippets.

@wr0ngway
Created September 13, 2010 23:42
Show Gist options
  • Save wr0ngway/578267 to your computer and use it in GitHub Desktop.
Save wr0ngway/578267 to your computer and use it in GitHub Desktop.
# origin of work
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://posterous.timocracy.com/the-trouble-with-bash-colored-prompts-munging
function parse_git_dirty {
status=`git status 2> /dev/null`
bits=''
if [[ "${status}" =~ "Changed but not updated" ]]; then
bits="${bits}*"
fi
if [[ "${status}" =~ "Untracked files" ]]; then
bits="${bits}?"
fi
if [[ "${status}" =~ "new file:" ]]; then
bits="${bits}+"
fi
if [[ "${status}" =~ "Your branch is ahead of" ]]; then
bits="${bits}^"
fi
if [[ "${status}" =~ "renamed:" ]]; then
bits="${bits}>"
fi
echo "${bits}"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1)/"
}
GREEN='\[\e[01;32m\]'
BLUE='\[\e[01;36m\]'
MAGENTA='\[\e[01;35m\]'
RED='\[\e[01;31m\]'
NO_COLOR='\[\e[00m\]'
END_COLOR='\[\e[m\]'
export PS1="${GREEN}\u${END_COLOR}@${BLUE}\h${END_COLOR} ${MAGENTA}\w${END_COLOR}\$(parse_git_branch)${RED}\$(parse_git_dirty)${END_COLOR}$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment