find_git_dirty: Added in check between staged and unstaged changes

This commit is contained in:
eacousineau
2013-03-19 14:51:29 -05:00
parent 226e2fc80b
commit c58bee1f67

View File

@@ -3,8 +3,8 @@ find_git_branch() {
# Based on: http://stackoverflow.com/a/13003854/170413
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
then
if [[ -z "$branch" ]]; then
branch='detached'
if [[ "$branch" == "HEAD" ]]; then
branch='(detached head)'
fi
git_branch="($branch)"
else
@@ -20,9 +20,15 @@ find_git_dirty() {
# Based on: http://stackoverflow.com/a/2659808/170413
if git diff-files --quiet
then
git_dirty=''
if git diff-index --quiet --cached HEAD
then
git_dirty=''
else
# Can't figure out different colors
git_dirty="^"
fi
else
git_dirty='*'
git_dirty="*"
fi
fi
}
@@ -30,7 +36,7 @@ find_git_dirty() {
PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
# Default Git enabled prompt with dirty state
# export PS1="\u@\h \w\[$txtcyn\]\$git_branch\[$txtylw\]\$git_dirty\[$txtrst\]\$ "
# export PS1="\u@\h \w\[$txtcyn\]\$git_branch\$git_dirty\[$txtrst\]\$ "
# Another variant:
# export PS1="\[$bldgrn\]\u@\h\[$txtrst\] \w\[$bldylw\]\$git_branch\[$txtcyn\]\$git_dirty\[$txtrst\]\$ "