Created
December 20, 2016 03:17
-
-
Save cwoodall/4c277b89a47d970f5a0c4fe59b434f07 to your computer and use it in GitHub Desktop.
My New Bash Prompt with Git Status
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
green() { | |
printf "\e[32m${1}\e[00m" | |
} | |
light_red() { | |
printf "\e[91m${1}\e[00m" | |
} | |
radioactive="\u2622" | |
check_mark="\u2714" | |
x_mark="\u2715" | |
prompt_if_git() { | |
git status > /dev/null 2> /dev/null | |
if [ $? -ne 0 ]; then | |
return | |
fi | |
printf "$1" | |
} | |
prompt_git_branch() { | |
git status > /dev/null 2> /dev/null | |
if [ $? -ne 0 ]; then | |
return | |
fi | |
git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/\1/" | |
} | |
prompt_git_status() { | |
git status > /dev/null 2> /dev/null | |
if [ $? -ne 0 ]; then | |
return | |
fi | |
git diff-index --quiet HEAD 2> /dev/null | |
case $? in | |
0) state_char=`green $radioactive`;; | |
*) state_char=`light_red $radioactive` ;; | |
esac | |
printf "$state_char" | |
} | |
did_last_fail () { | |
case $? in | |
0) printf "$(green $check_mark)" ;; | |
*) printf "$(light_red $x_mark)" ;; | |
esac | |
} | |
export PS1="\$(did_last_fail) \u@\h \w \$(prompt_if_git [)\$(prompt_git_branch)\$(prompt_git_status)\$(prompt_if_git ])\n$ " | |
export PROMPT_DIRTRIM=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment