Created
December 17, 2010 00:04
-
-
Save benhamill/744248 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 "$RED⚡" | |
echo 'dirty' | |
fi | |
} | |
function ps1_function { | |
export PS1="$DARK_GREY[\@]$NORMAL \u$LIGHT_GREY@$NORMAL\h:$BLUE\w$NORMAL$(parse_git_branch)$ " | |
} | |
export PROMPT_COMMAND='ps1_function' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment