fish-shell/share/functions/__fish_print_pipestatus.fish
Johannes Altmanninger 55bc6a27c6 Make prompts forward compatible with fish 3.1.2 by passing locally exported variable
Commit 5d135d555 (prompts: fix pipestatus for jobs prefixed with "not")
introduced a backwards compatibility hack about adding an optional argument
to __fish_print_pipestatus. This hack would break downgrading to fish 3.1.2
if the user copied the new prompt to their config - they would get a backtrace
on every prompt which is arguably worse than the patch's minor improvement.

This does away with the error trace - old fish just won't show the fancy
new pipestatus on `not true`.

Implemented by passing the last $status as the poor man's kwarg, which works
since 3.1.0 (9b86d5dd1 Export all local exported variables in a new scope).

The prompts don't work with fish 3.0.0 or older; downgrading does not seem
too important in general but I think this patch is an okay simplification.
2020-09-05 09:58:55 +02:00

28 lines
1.2 KiB
Fish

function __fish_print_pipestatus --description "Print pipestatus for prompt"
set -l last_status
if set -q __fish_last_status
set last_status $__fish_last_status
else
set last_status $argv[-1] # default to $pipestatus[-1]
end
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]
set -e argv[1 2 3 4 5]
# Only print status codes if the job failed.
# SIGPIPE (141 = 128 + 13) is usually not a failure, see #6375.
if test $last_status -ne 0 && test $last_status -ne 141
set -l sep (set_color normal){$brace_sep_color}{$separator}(set_color normal){$status_color}
set -l last_pipestatus_string (string join "$sep" (__fish_pipestatus_with_signal $argv))
set -l last_status_string ""
if test $last_status -ne $argv[-1]
set last_status_string " "$status_color$last_status
end
printf "%s%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 $last_status_string (set_color normal)
end
end