Skip to content

Instantly share code, notes, and snippets.

@benhamill
Created December 17, 2010 00:04
Show Gist options
  • Save benhamill/744248 to your computer and use it in GitHub Desktop.
Save benhamill/744248 to your computer and use it in GitHub Desktop.
#! /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