Last active
August 29, 2015 14:01
-
-
Save caspian311/6c1d8d1ccf947e1e3c98 to your computer and use it in GitHub Desktop.
bash prompt with git status
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
| RED="\[\033[0;31m\]" | |
| YELLOW="\[\033[0;33m\]" | |
| GREEN="\[\033[0;32m\]" | |
| WHITE="\[\033[1;37m\]" | |
| function parse_git_branch { | |
| ref=$(git symbolic-ref HEAD 2> /dev/null) || return | |
| foo=${ref#refs/heads/} | |
| status=$(git status -s | awk '{print $1}' 2>&1) | |
| echo "$status" | grep M > /dev/null 2>&1 | |
| changes=$? | |
| echo "$status" | grep '??' > /dev/null 2>&1 | |
| newFiles=$? | |
| echo "$status" | grep 'D' > /dev/null 2>&1 | |
| delFiles=$? | |
| if [ $changes = 0 ] | |
| then | |
| foo="$foo*" | |
| fi | |
| if [ $newFiles = 0 ] | |
| then | |
| foo="$foo+" | |
| fi | |
| if [ $delFiles = 0 ] | |
| then | |
| foo="$foo-" | |
| fi | |
| echo "($foo)" | |
| } | |
| PS1="$WHITE[$GREEN\u@\h:\w$WHITE]$YELLOW\$(parse_git_branch)$GREEN\$ " |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
largely stolen from http://www.railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/