Created
November 18, 2011 14:34
-
-
Save shreyansb/1376607 to your computer and use it in GitHub Desktop.
improved git branch status in your bash 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
| txtred='\033[1;31m' | |
| txtgrn='\033[1;32m' | |
| txtylw='\033[1;33m' | |
| end='\033[0m' | |
| function parse_git { | |
| branch="$(__git_ps1 "%s")" | |
| if [[ -z $branch ]]; then | |
| return | |
| fi | |
| status="$(git status 2>/dev/null)" | |
| if [[ $status =~ "Untracked files" ]]; then | |
| branch="${txtred}(${branch})${end}" | |
| elif [[ $status =~ "Changes not staged for commit" ]]; then | |
| branch="${txtred}(${branch})${end}" | |
| elif [[ $status =~ "Changes to be committed" ]]; then | |
| branch="${txtylw}(${branch})${end}" | |
| elif [[ $status =~ "Your branch is ahead" ]]; then | |
| branch="${txtylw}(${branch})${end}" | |
| elif [[ $status =~ "nothing to commit" ]]; then | |
| branch="${txtgrn}(${branch})${end}" | |
| fi | |
| echo -e $branch | |
| } | |
| PS1='[\u@$HOSTNAME \[\e[2;32m\]\w\[\e[m\] $(parse_git)]\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment