2019-02-28 06:19:09 +00:00
|
|
|
function __fish_print_pipestatus --description "Print pipestatus for prompt"
|
2020-02-03 07:53:41 +00:00
|
|
|
set -l last_status
|
2020-09-05 07:16:49 +00:00
|
|
|
if set -q __fish_last_status
|
|
|
|
set last_status $__fish_last_status
|
2020-02-03 07:53:41 +00:00
|
|
|
else
|
|
|
|
set last_status $argv[-1] # default to $pipestatus[-1]
|
|
|
|
end
|
2019-03-05 18:19:57 +00:00
|
|
|
set -l left_brace $argv[1]
|
|
|
|
set -l right_brace $argv[2]
|
|
|
|
set -l separator $argv[3]
|
2021-01-24 13:25:34 +00:00
|
|
|
set -l brace_sep_color $argv[4]
|
|
|
|
set -l status_color $argv[5]
|
2020-09-24 18:08:16 +00:00
|
|
|
|
2019-02-28 06:19:09 +00:00
|
|
|
set -e argv[1 2 3 4 5]
|
|
|
|
|
2021-01-24 13:25:34 +00:00
|
|
|
if not set -q argv[1]
|
|
|
|
echo error: missing argument >&2
|
2021-03-07 11:50:21 +00:00
|
|
|
status print-stack-trace >&2
|
2021-01-24 13:25:34 +00:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2020-02-03 07:53:41 +00:00
|
|
|
# Only print status codes if the job failed.
|
2020-03-07 13:13:58 +00:00
|
|
|
# SIGPIPE (141 = 128 + 13) is usually not a failure, see #6375.
|
2020-09-24 18:08:16 +00:00
|
|
|
if not contains $last_status 0 141
|
|
|
|
set -l sep $brace_sep_color$separator$status_color
|
2021-01-03 14:15:57 +00:00
|
|
|
set -l last_pipestatus_string (fish_status_to_signal $argv | string join "$sep")
|
2020-02-03 07:53:41 +00:00
|
|
|
set -l last_status_string ""
|
2021-01-22 20:54:59 +00:00
|
|
|
if test "$last_status" -ne "$argv[-1]"
|
2020-02-03 07:53:41 +00:00
|
|
|
set last_status_string " "$status_color$last_status
|
|
|
|
end
|
2021-03-03 18:20:28 +00:00
|
|
|
set -l normal (set_color normal)
|
|
|
|
# The "normal"s are to reset modifiers like bold - see #7771.
|
|
|
|
printf "%s" $normal $brace_sep_color $left_brace \
|
2020-11-22 13:39:48 +00:00
|
|
|
$status_color $last_pipestatus_string \
|
2021-03-03 18:20:28 +00:00
|
|
|
$normal $brace_sep_color $right_brace $normal $last_status_string $normal
|
2019-02-28 06:19:09 +00:00
|
|
|
end
|
|
|
|
end
|