prompt: don't print status of last process in pipe twice

If a command fails, print the pipestatus in red instead of yellow and
don't print the status of the last process again. See #6375.

Also use $fish_color_status for coloring status consistently.

Also use __fish_pipestatus_with_signal to print SIGPIPE instead
of a numeric code on e.g.: yes | less +q

[ci skip]
This commit is contained in:
Johannes Altmanninger 2019-12-10 22:32:35 +01:00
parent eaa87ff885
commit 6902459566
6 changed files with 20 additions and 39 deletions

View file

@ -6,10 +6,8 @@ function __fish_print_pipestatus --description "Print pipestatus for prompt"
set -l status_color $argv[5]
set -e argv[1 2 3 4 5]
# only output $pipestatus if there was a pipe
# and any part of it but the last one had non-zero exit status
# if only the last process failed, prompts already print $status which is $pipestatus[-1]
if set -q argv[2] && string match -qvr '^0$' $argv[1..-2]
# only output status codes if some process in the pipe failed
if string match -qvr '^0$' $argv
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))
printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal )$brace_sep_color $left_brace \

View file

@ -3,7 +3,6 @@
function fish_prompt --description 'Write out the prompt'
set -l last_pipestatus $pipestatus
set -l last_status $status
set -l normal (set_color normal)
# Initialize our variables.
@ -26,10 +25,7 @@ function fish_prompt --description 'Write out the prompt'
end
# Write pipestatus
set -l prompt_status (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
if test $last_status -ne 0
set prompt_status " $prompt_status" (set_color $fish_color_status) "[$last_status]" "$normal"
end
set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " "
end

View file

@ -4,13 +4,11 @@
function fish_prompt --description "Write out the prompt"
# Save our status
set -l last_pipestatus $pipestatus
set -l last_status $status
__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus
set -q fish_color_status
or set -U fish_color_status red
if test $last_status -ne 0
printf "%s(%s)%s " (set_color red --bold) (__fish_status_to_signal $last_status) (set_color normal)
end
__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus
set -l color_cwd
set -l suffix

View file

@ -26,10 +26,7 @@ function fish_prompt --description 'Write out the prompt'
end
# Write pipestatus
set -l prompt_status (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
if test $last_status -ne 0
set prompt_status " $prompt_status" (set_color $fish_color_status) "[$last_status]" "$normal"
end
set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal $prompt_status $suffix " "
end

View file

@ -4,14 +4,9 @@
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
set -l last_status $status
#Set the color for the status depending on the value
if test $stat -gt 0
set -l status_color (set_color brred)
else
set -l status_color (set_color brgreen)
end
set -q fish_color_status
or set -U fish_color_status red
switch "$USER"
case root toor
@ -20,11 +15,11 @@ function fish_prompt --description 'Informative prompt'
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) \
(set_color bryellow) $last_pipestatus)
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '[%s] %s%s@%s %s%s %s%s(%s)%s \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD "$pipestatus_string" \
$status_color $last_status (set_color normal)
printf '[%s] %s%s@%s %s%s %s%s%s \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
(set_color normal)
end
end

View file

@ -3,7 +3,6 @@
function fish_prompt --description 'Write out the prompt'
set -l last_pipestatus $pipestatus
set -l last_status $status
if not set -q __fish_git_prompt_show_informative_status
set -g __fish_git_prompt_show_informative_status 1
@ -57,6 +56,9 @@ function fish_prompt --description 'Write out the prompt'
set -g __fish_git_prompt_color_cleanstate green --bold
end
set -q fish_color_status
or set -U fish_color_status red
set -l color_cwd
set -l prefix
set -l suffix
@ -80,14 +82,9 @@ function fish_prompt --description 'Write out the prompt'
printf '%s ' (fish_vcs_prompt)
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
echo -n "$pipestatus_string"
if not test $last_status -eq 0
set_color $fish_color_error
echo -n "[$last_status] "
set_color normal
end
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
echo -n $pipestatus_string
set_color normal
echo -n "$suffix "
end