From 8ebbe67ff1d0b02c55e7fa0ad0bd6b11bd1e7f7c Mon Sep 17 00:00:00 2001 From: zabereer Date: Wed, 27 Feb 2019 06:11:03 +0000 Subject: [PATCH] Use `string match` instead of `for` loop to simplify classic_status.fish --- .../web_config/sample_prompts/classic_status.fish | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/share/tools/web_config/sample_prompts/classic_status.fish b/share/tools/web_config/sample_prompts/classic_status.fish index c117ab501..0618fc9bd 100644 --- a/share/tools/web_config/sample_prompts/classic_status.fish +++ b/share/tools/web_config/sample_prompts/classic_status.fish @@ -7,15 +7,9 @@ function fish_prompt --description "Write out the prompt" set -l last_status $status # only output $pipestatus if there was a pipe and any part of it had non-zero exit status - # TODO maybe have a common function that returns true if all array elements match a certain value? - if test (count $last_pipestatus) -gt 1 - for pstat in $last_pipestatus - if test $pstat -ne 0 - set -l last_pipestatus_string (string join "|" (__fish_pipestatus_with_signal $last_pipestatus)) - printf "%s[%s]%s " (set_color yellow --bold) $last_pipestatus_string (set_color normal) - break - end - end + if test (count $last_pipestatus) -gt 1 && string match -qvr '^0$' $last_pipestatus + set -l last_pipestatus_string (string join "|" (__fish_pipestatus_with_signal $last_pipestatus)) + printf "%s[%s]%s " (set_color yellow --bold) $last_pipestatus_string (set_color normal) end if test $last_status -ne 0