Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Created May 12, 2014 15:15
Show Gist options
  • Save skinofstars/6caf821ebb6e661963be to your computer and use it in GitHub Desktop.
Save skinofstars/6caf821ebb6e661963be to your computer and use it in GitHub Desktop.
# what i'm using for my bash git prompt today
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"
function parse_git_dirty () {
git_status="$(git status 2> /dev/null)"
if [[ ${git_status} =~ "On branch" ]]; then
if [[ ! ${git_status} =~ "working directory clean" ]]; then
echo "${RED}⚡${COLOR_NONE}"
fi
fi
}
function parse_git_branch_simple () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function prompt_func() {
previous_return_value=$?;
prompt="\w${GREEN}$(parse_git_branch_simple)${COLOR_NONE}$(parse_git_dirty)"
PS1="${prompt} $ "
}
PROMPT_COMMAND=prompt_func
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment