Created
February 22, 2015 16:57
-
-
Save akora/d9f9105786ca541712b2 to your computer and use it in GitHub Desktop.
Mac OS Yosemite Git aware (two-line) bash prompt
This file contains 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
# settings for the main prompt | |
BLUE="\[\e[44;36m\]" | |
PATH_SHORT="\w" | |
COLOR_RESET="\[\e[0m\]" | |
NEW_LINE="\n" | |
# RAG colors indicating git status | |
RED="\[\033[0;31m\]" | |
AMBER="\[\033[0;33m\]" | |
GREEN="\[\033[0;32m\]" | |
NO_COLOR="\[\033[0m\]" | |
# thanks https://gist.github.com/maumercado for the below functions! | |
function parse_git_branch () { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
function set_git_branch () { | |
# capture the output of the "git status" command | |
git_status="$(git status 2> /dev/null)" | |
# set color based on clean/staged/dirty | |
if [[ ${git_status} =~ .*"working directory clean".* ]]; then | |
B_STATE="${GREEN}" | |
elif [[ ${git_status} =~ .*"Changes to be committed".* ]]; then | |
B_STATE="${AMBER}" | |
else | |
B_STATE="${RED}" | |
fi | |
} | |
prompt_cmd () { | |
set_git_branch | |
PS1="$BLUE$PATH_SHORT$COLOR_RESET ${B_STATE}\$(parse_git_branch)$NO_COLOR$NEW_LINE[\u@\h] $ " | |
} | |
# override Xcode's git version with a newer one (installed by SourceTree) | |
export PATH="/usr/local/git/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:$PATH" | |
PROMPT_COMMAND=prompt_cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment