Last active
August 29, 2015 13:59
-
-
Save zeroeth/10919941 to your computer and use it in GitHub Desktop.
bash-git-prompt
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
| # You can find this by searching for git bash prompts. Mine removed the unicode symbols. | |
| # just insert it into your prompt as $(git_prompt) | |
| # Colors for scripts | |
| CLR="\[\033[0m\]" # unsets color to term's fg color | |
| # regular colors | |
| BLK="\[\033[0;30m\]" # black | |
| RED="\[\033[0;31m\]" # red | |
| GRN="\[\033[0;32m\]" # green | |
| YLW="\[\033[0;33m\]" # yellow | |
| BLU="\[\033[0;34m\]" # blue | |
| MGN="\[\033[0;35m\]" # magenta | |
| CYN="\[\033[0;36m\]" # cyan | |
| WHT="\[\033[0;37m\]" # white | |
| # emphasized (bolded) colors | |
| EBLK="\[\033[1;30m\]" | |
| ERED="\[\033[1;31m\]" | |
| EGRN="\[\033[1;32m\]" | |
| EYLW="\[\033[1;33m\]" | |
| EBLU="\[\033[1;34m\]" | |
| EMGN="\[\033[1;35m\]" | |
| ECYN="\[\033[1;36m\]" | |
| EWHY="\[\033[1;37m\]" | |
| # background colors | |
| BGBLK="\[\033[40m\]" | |
| BGRED="\[\033[41m\]" | |
| BGGRN="\[\033[42m\]" | |
| BGYLY="\[\033[43m\]" | |
| BGBLU="\[\033[44m\]" | |
| BGMGN="\[\033[45m\]" | |
| BGCYN="\[\033[46m\]" | |
| BGWHT="\[\033[47m\]" | |
| function git_prompt { | |
| \git rev-parse --git-dir &> /dev/null | |
| git_status="$(git status 2> /dev/null)" | |
| branch_pattern="^On branch ([^${IFS}]*)" | |
| remote_pattern="Your branch is (.*) (of|with)" | |
| diverge_pattern="Your branch and (.*) have diverged" | |
| if [[ ! ${git_status}} =~ "working directory clean" ]]; then | |
| state="${RED}/" #⚡ | |
| fi | |
| # add an else if or two here if you want to get more specific | |
| if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
| if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
| remote="${YLW}+" #↑ | |
| else | |
| remote="${YLW}-" #↓ | |
| fi | |
| fi | |
| if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
| remote="${YLW}%" #↕ | |
| fi | |
| if [[ ${git_status} =~ ${branch_pattern} ]]; then | |
| branch=${BASH_REMATCH[1]} | |
| echo "%${branch}${remote}${state}" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment