Created
April 25, 2013 18:43
-
-
Save jcantrell-trulia/5462058 to your computer and use it in GitHub Desktop.
Git Prompt for bash
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
| _git_info() { | |
| ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
| echo "${ref#refs/heads/} " | |
| } | |
| # Checks if working tree is dirty | |
| _git_dirty() { | |
| if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then | |
| #dirty | |
| echo -e $GIT_DIRTY | |
| else | |
| #clean | |
| echo "" | |
| fi | |
| } | |
| # Checks if there are commits ahead from remote | |
| _git_ahead() { | |
| ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
| if $(echo "$(git log origin/${ref#refs/heads/}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then | |
| echo -e $GIT_AHEAD | |
| fi | |
| } | |
| PROMPT_HI="\[\e[1;34m\]"; | |
| PROMPT_LOW="\[\e[0;34m\]"; | |
| PROMPT_DEFAULT="\[\e[0m\]"; | |
| GIT_BRANCH="\[\e[0;32m\]"; | |
| GIT_AHEAD="\e[1;32m±"; | |
| GIT_DIRTY="\e[1;33m"; | |
| PS1="\$(_git_ahead)$GIT_BRANCH\$(_git_dirty)\$(_git_info)$PROMPT_HI\W$PROMPT_LOW ➤ $PROMPT_DEFAULT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment