From c58bee1f677e3ed62a86c75573a504054e3b82f4 Mon Sep 17 00:00:00 2001 From: eacousineau Date: Tue, 19 Mar 2013 14:51:29 -0500 Subject: [PATCH] find_git_dirty: Added in check between staged and unstaged changes --- prompt.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/prompt.sh b/prompt.sh index 67e66b0..d60fe9f 100644 --- a/prompt.sh +++ b/prompt.sh @@ -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\]\$ "