-
-
Save hmcfletch/965595 to your computer and use it in GitHub Desktop.
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
DEFAULT="\[\033[1;00m\]" | |
BLACK="\[\033[1;30m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[1;32m\]" | |
WHITE="\[\033[1;37m\]" | |
BLUE="\[\033[1;36m\]" | |
# Returns "*" if the current git branch is dirty. | |
function parse_git_dirty { | |
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "*" | |
} | |
# Returns "|shashed:N" where N is the number of stashed states (if any). | |
function parse_git_stash { | |
local stash=`expr $(git stash list 2>/dev/null| wc -l)` | |
if [ "$stash" != "0" ] | |
then | |
echo "|stashed:$stash" | |
fi | |
} | |
# Get the current git branch name (if available) | |
git_prompt() { | |
local ref=$(git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3) | |
if [ "$ref" != "" ] | |
then | |
echo "($ref$(parse_git_dirty)$(parse_git_stash)) " | |
fi | |
} | |
export PS1="[$GREEN\u:$YELLOW\w$DEFAULT]$BLUE \$(git_prompt)\$ $DEFAULT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment