From aa37b40d934a613a9cd3772ddf10cf7d24d5a0a9 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 27 Sep 2015 16:30:37 +0200 Subject: [PATCH] __fish_hg_prompt: Clean up a bit `sort -u | uniq` is completely redundant, calling grep for every status-pair is unnecessary, `contains` doesn't take the word "in" as special. None of these are critical and there's basically no performance benefit since this function is utterly dominated by hg calls. --- share/functions/__fish_hg_prompt.fish | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/share/functions/__fish_hg_prompt.fish b/share/functions/__fish_hg_prompt.fish index fa25cb353..20a6d3ba2 100644 --- a/share/functions/__fish_hg_prompt.fish +++ b/share/functions/__fish_hg_prompt.fish @@ -43,7 +43,7 @@ function __fish_hg_prompt --description 'Write out the hg prompt' echo -n '|' - set -l repo_status (hg status |cut -c 1-2|sort -u|uniq) + set -l repo_status (hg status | cut -c 1-2 | sort -u) # Show nice color for a clean repo if test -z "$repo_status" @@ -54,16 +54,10 @@ function __fish_hg_prompt --description 'Write out the hg prompt' # Handle modified or dirty (unknown state) else set -l hg_statuses - set -l modified # Take actions for the statuses of the files in the repo for line in $repo_status - # Determine if we are modified or dirty - if echo $line | grep -qc '^[AMCD]' - set modified 1 - end - # Add a character for each file status if we have one switch $line case 'A ' ; set hg_statuses $hg_statuses added @@ -75,7 +69,7 @@ function __fish_hg_prompt --description 'Write out the hg prompt' end end - if set -q modified[1] + if string match -r '^[AMCD]' $repo_status set_color $fish_color_hg_modified else set_color $fish_color_hg_dirty @@ -85,7 +79,7 @@ function __fish_hg_prompt --description 'Write out the hg prompt' # Sort status symbols for i in $fish_prompt_hg_status_order - if contains $i in $hg_statuses + if contains -- $i $hg_statuses set -l color_name fish_color_hg_$i set -l status_name fish_prompt_hg_status_$i