Created
December 16, 2010 23:24
-
-
Save benhamill/744205 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[1;32m\]" | |
BLUE="\[\033[1;34m\]" | |
DARK_GREY="\[\033[0;30m\]" | |
LIGHT_GREY="\[\033[0;37m\]" | |
NORMAL="\[\033[0m\]" | |
function parse_git_branch { | |
git_status="$(git status 2> /dev/null)" | |
pattern="^# On branch ([^${IFS}]*)" | |
if [[ ${git_status} =~ ${pattern} ]]; then | |
branch=${BASH_REMATCH[1]} | |
if [[ $(parse_git_dirty) == 'clean' ]]; then | |
result="${GREEN}[${branch}]${NORMAL}" | |
else | |
result="${RED}[${branch}]${NORMAL}" | |
fi | |
echo " ${result}" | |
fi | |
} | |
function parse_git_dirty { | |
git_status="$(git status 2> /dev/null)" | |
if [[ ${git_status} =~ "working directory clean" ]]; then | |
echo 'clean' | |
else | |
echo 'dirty' | |
fi | |
} | |
export PS1="$DARK_GREY[\@]$NORMAL \u$LIGHT_GREY@$NORMAL\h:$BLUE\w$NORMAL\$(parse_git_branch)$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment