From b79854ad1aa814d9d35d76a1929b4726fa4bffa5 Mon Sep 17 00:00:00 2001 From: Terje Larsen Date: Wed, 14 Nov 2012 23:48:12 +0100 Subject: [PATCH] Optimize staged logic --- share/functions/__terlar_git_prompt.fish | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/share/functions/__terlar_git_prompt.fish b/share/functions/__terlar_git_prompt.fish index afdd7b3eb..afe5904c5 100644 --- a/share/functions/__terlar_git_prompt.fish +++ b/share/functions/__terlar_git_prompt.fish @@ -37,16 +37,14 @@ function __terlar_git_prompt --description 'Write out the git prompt' return end - if printf '%s\n' $index|grep '^[AMRCD]' >/dev/null - set_color $fish_color_git_staged - else - set_color $fish_color_git_dirty - end - - echo -n $branch'⚡' - set -l gs + set -l staged + for i in $index + if echo $i | grep '^[AMRCD]' >/dev/null + set staged 1 + end + switch $i case 'A ' ; set gs $gs added case 'M ' ' M' ; set gs $gs modified @@ -58,6 +56,14 @@ function __terlar_git_prompt --description 'Write out the git prompt' end end + if set -q staged[1] + set_color $fish_color_git_staged + else + set_color $fish_color_git_dirty + end + + echo -n $branch'⚡' + for i in $fish_prompt_git_status_order if contains $i in $gs set -l color_name fish_color_git_$i