mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
5d135d5556
6902459566
was an attempt to not print
$status twice in the prompt. As a result we print $pipestatus but
not $status, which /usually/ is the same as $pipestatus[-1] --- unless
the builtin "not" is used, which inverts the $status of a job (it does
not alter $pipestatus).
As a result, the default prompt prints unexpected status codes:
~ > not false
~ [1]> not true
~ > not true | true
~ > not false | false
~ [1|1]>
This commit reintroduces printing of $status after $pipestatus, but only
if it is different from $pipestatus[-1].
Additionally, we only print anything at all if the $status is nonzero,
to avoid confusing output on `not false | false`
~ > not false
~ > not true
~ [0] 1> not true | true
~ [0|0] 1> not false | false
~ >
I think this is closer to users' expectations for those cases; they should
not have to think about this implementation detail of the not-statement.
28 lines
1.2 KiB
Fish
28 lines
1.2 KiB
Fish
function __fish_print_pipestatus --description "Print pipestatus for prompt"
|
|
# take $status as optional argument to maintain compatibility
|
|
set -l last_status
|
|
if set last_status (string match -r -- '^\d+$' $argv[1])
|
|
set -e argv[1]
|
|
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.
|
|
if test $last_status -ne 0
|
|
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
|