aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__terlar_git_prompt.fish
diff options
context:
space:
mode:
authorGravatar Terje Larsen <terlar@gmail.com>2012-10-19 00:54:55 +0200
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-10-20 12:52:53 -0700
commit239d43dac4b8f4def3d284cdcd90b1154463f621 (patch)
tree22c6626d84985eb287da59ac5a408a10c8f03afb /share/functions/__terlar_git_prompt.fish
parent8a63326411b2acefff6b66a5595531b5f8b47ebf (diff)
Improve the git prompt
- Fix branch for older git version (--short for symbolic-ref was not available on git 1.7.9.5) - Use index (git status) for checking if staged - Add status indication for copied - Remove variables for statuses (less litter in the variables) - Remove usage of eval to echo and set_color - Replace printf where possible with echo -n
Diffstat (limited to 'share/functions/__terlar_git_prompt.fish')
-rw-r--r--share/functions/__terlar_git_prompt.fish84
1 files changed, 44 insertions, 40 deletions
diff --git a/share/functions/__terlar_git_prompt.fish b/share/functions/__terlar_git_prompt.fish
index 93df408f..3c80e2cb 100644
--- a/share/functions/__terlar_git_prompt.fish
+++ b/share/functions/__terlar_git_prompt.fish
@@ -1,75 +1,79 @@
set -gx fish_color_git_clean green
-set -gx fish_color_git_dirty red
-set -gx fish_color_git_ahead red
set -gx fish_color_git_staged yellow
+set -gx fish_color_git_dirty red
set -gx fish_color_git_added green
set -gx fish_color_git_modified blue
set -gx fish_color_git_renamed magenta
+set -gx fish_color_git_copied magenta
set -gx fish_color_git_deleted red
-set -gx fish_color_git_unmerged yellow
-set -gx fish_color_git_untracked cyan
-
-set -gx fish_prompt_git_status_added '✚'
-set -gx fish_prompt_git_status_modified '*'
-set -gx fish_prompt_git_status_renamed '➜'
-set -gx fish_prompt_git_status_deleted '✖'
-set -gx fish_prompt_git_status_unmerged '═'
-set -gx fish_prompt_git_status_untracked '.'
+set -gx fish_color_git_untracked yellow
+set -gx fish_color_git_unmerged red
function __terlar_git_prompt --description 'Write out the git prompt'
- set -l branch (git symbolic-ref --quiet --short HEAD 2>/dev/null)
+ set -l branch (git rev-parse --abbrev-ref HEAD ^/dev/null)
if test -z $branch
return
end
echo -n '|'
- set -l index (git status --porcelain 2>/dev/null)
+ set -l index (git status --porcelain ^/dev/null|cut -c 1-2|uniq)
+
if test -z "$index"
set_color $fish_color_git_clean
- printf $branch'✓'
+ echo -n $branch'✓'
set_color normal
return
end
- git diff-index --quiet --cached HEAD 2>/dev/null
- set -l staged $status
- if test $staged = 1
+ if printf '%s\n' $index|grep '^[ADRCM]' >/dev/null
set_color $fish_color_git_staged
else
set_color $fish_color_git_dirty
end
- printf $branch'⚡'
+ echo -n $branch'⚡'
- set -l info
for i in $index
switch $i
- case 'A *'
- set i added
- case 'M *' ' M *'
- set i modified
- case 'R *'
- set i renamed
- case 'D *' ' D *'
- set i deleted
- case 'U *'
- set i unmerged
- case '?? *'
- set i untracked
- end
-
- if not contains $i $info
- set info $info $i
+ case 'A ' ; set added
+ case 'M ' ' M' ; set modified
+ case 'R ' ; set renamed
+ case 'C ' ; set copied
+ case 'D ' ' D' ; set deleted
+ case '??' ; set untracked
+ case 'U*' '*U' 'DD' 'AA'; set unmerged
end
end
- for i in added modified renamed deleted unmerged untracked
- if contains $i $info
- eval 'set_color $fish_color_git_'$i
- eval 'printf $fish_prompt_git_status_'$i
- end
+ if set -q added
+ set_color $fish_color_git_added
+ echo -n '✚'
+ end
+ if set -q modified
+ set_color $fish_color_git_modified
+ echo -n '*'
+ end
+ if set -q renamed
+ set_color $fish_color_git_renamed
+ echo -n '➜'
+ end
+ if set -q copied
+ set_color $fish_color_git_copied
+ echo -n '⇒'
+ end
+ if set -q deleted
+ set_color $fish_color_git_deleted
+ echo -n '✖'
+ end
+ if set -q untracked
+ set_color $fish_color_git_untracked
+ echo -n '?'
+ end
+ if set -q unmerged
+ set_color $fish_color_git_unmerged
+ echo -n '!'
end
set_color normal