From d5c18350a76d514b3c56cb9a683e30e2f5fe6f19 Mon Sep 17 00:00:00 2001 From: zabereer Date: Fri, 1 Mar 2019 19:55:28 +0000 Subject: [PATCH] use global variables for `$pipestatus` in prompts to allow users to customize the look --- share/functions/__fish_print_pipestatus.fish | 38 ++++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/share/functions/__fish_print_pipestatus.fish b/share/functions/__fish_print_pipestatus.fish index 6851d7791..ecd0ec989 100644 --- a/share/functions/__fish_print_pipestatus.fish +++ b/share/functions/__fish_print_pipestatus.fish @@ -1,19 +1,35 @@ function __fish_print_pipestatus --description "Print pipestatus for prompt" - # maybe these could be in global variables similar to __fish_color_status to allow - # users to set the variables to modify the braces/separator/color used - set -l left_brace $argv[1] - set -l right_brace $argv[2] - set -l separator $argv[3] - set -l brace_sep_color $argv[4] - set -l status_color $argv[5] + + # allow users to customize these variables + if not set -q __fish_prompt_pipestatus_left_brace + set -g __fish_prompt_pipestatus_left_brace $argv[1] + end + + if not set -q __fish_prompt_pipestatus_right_brace + set -g __fish_prompt_pipestatus_right_brace $argv[2] + end + + if not set -q __fish_prompt_pipestatus_separator + set -g __fish_prompt_pipestatus_separator $argv[3] + end + + if not set -q __fish_prompt_pipestatus_brace_sep_color + set -g __fish_prompt_pipestatus_brace_sep_color $argv[4] + end + + if not set -q __fish_prompt_pipestatus_color + set -g __fish_prompt_pipestatus_color $argv[5] + end + set -e argv[1 2 3 4 5] # only output $pipestatus if there was a pipe and any part of it had non-zero exit status if set -q argv[2] && string match -qvr '^0$' $argv - set -l sep (set_color normal){$brace_sep_color}{$separator}(set_color normal){$status_color} + set -l sep (set_color normal){$__fish_prompt_pipestatus_brace_sep_color}{$__fish_prompt_pipestatus_separator}(set_color normal){$__fish_prompt_pipestatus_color} set -l last_pipestatus_string (string join "$sep" (__fish_pipestatus_with_signal $argv)) - printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal )$brace_sep_color $left_brace \ - (set_color normal) $status_color $last_pipestatus_string (set_color normal) \ - $brace_sep_color $right_brace (set_color normal) + printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal) $__fish_prompt_pipestatus_brace_sep_color \ + $__fish_prompt_pipestatus_left_brace (set_color normal) $__fish_prompt_pipestatus_color \ + $last_pipestatus_string (set_color normal) $__fish_prompt_pipestatus_brace_sep_color \ + $__fish_prompt_pipestatus_right_brace (set_color normal) end end