mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-15 22:44:01 +00:00
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:
parent
eaa87ff885
commit
6902459566
6 changed files with 20 additions and 39 deletions
|
@ -6,10 +6,8 @@ function __fish_print_pipestatus --description "Print pipestatus for prompt"
|
||||||
set -l status_color $argv[5]
|
set -l status_color $argv[5]
|
||||||
set -e argv[1 2 3 4 5]
|
set -e argv[1 2 3 4 5]
|
||||||
|
|
||||||
# only output $pipestatus if there was a pipe
|
# only output status codes if some process in the pipe failed
|
||||||
# and any part of it but the last one had non-zero exit status
|
if string match -qvr '^0$' $argv
|
||||||
# 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]
|
|
||||||
set -l sep (set_color normal){$brace_sep_color}{$separator}(set_color normal){$status_color}
|
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_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 \
|
printf "%s%s%s%s%s%s%s%s%s%s" (set_color normal )$brace_sep_color $left_brace \
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
function fish_prompt --description 'Write out the prompt'
|
function fish_prompt --description 'Write out the prompt'
|
||||||
set -l last_pipestatus $pipestatus
|
set -l last_pipestatus $pipestatus
|
||||||
set -l last_status $status
|
|
||||||
set -l normal (set_color normal)
|
set -l normal (set_color normal)
|
||||||
|
|
||||||
# Initialize our variables.
|
# Initialize our variables.
|
||||||
|
@ -26,10 +25,7 @@ function fish_prompt --description 'Write out the prompt'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write pipestatus
|
# Write pipestatus
|
||||||
set -l prompt_status (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
|
||||||
if test $last_status -ne 0
|
|
||||||
set prompt_status " $prompt_status" (set_color $fish_color_status) "[$last_status]" "$normal"
|
|
||||||
end
|
|
||||||
|
|
||||||
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 " "
|
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
|
end
|
||||||
|
|
|
@ -4,13 +4,11 @@
|
||||||
function fish_prompt --description "Write out the prompt"
|
function fish_prompt --description "Write out the prompt"
|
||||||
# Save our status
|
# Save our status
|
||||||
set -l last_pipestatus $pipestatus
|
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
|
__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus
|
||||||
printf "%s(%s)%s " (set_color red --bold) (__fish_status_to_signal $last_status) (set_color normal)
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l color_cwd
|
set -l color_cwd
|
||||||
set -l suffix
|
set -l suffix
|
||||||
|
|
|
@ -26,10 +26,7 @@ function fish_prompt --description 'Write out the prompt'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write pipestatus
|
# Write pipestatus
|
||||||
set -l prompt_status (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
set -l prompt_status (__fish_print_pipestatus " [" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
|
||||||
if test $last_status -ne 0
|
|
||||||
set prompt_status " $prompt_status" (set_color $fish_color_status) "[$last_status]" "$normal"
|
|
||||||
end
|
|
||||||
|
|
||||||
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 " "
|
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
|
end
|
||||||
|
|
|
@ -4,14 +4,9 @@
|
||||||
function fish_prompt --description 'Informative prompt'
|
function fish_prompt --description 'Informative prompt'
|
||||||
#Save the return status of the previous command
|
#Save the return status of the previous command
|
||||||
set -l last_pipestatus $pipestatus
|
set -l last_pipestatus $pipestatus
|
||||||
set -l last_status $status
|
|
||||||
|
|
||||||
#Set the color for the status depending on the value
|
set -q fish_color_status
|
||||||
if test $stat -gt 0
|
or set -U fish_color_status red
|
||||||
set -l status_color (set_color brred)
|
|
||||||
else
|
|
||||||
set -l status_color (set_color brgreen)
|
|
||||||
end
|
|
||||||
|
|
||||||
switch "$USER"
|
switch "$USER"
|
||||||
case root toor
|
case root toor
|
||||||
|
@ -20,11 +15,11 @@ function fish_prompt --description 'Informative prompt'
|
||||||
or set_color $fish_color_cwd) \
|
or set_color $fish_color_cwd) \
|
||||||
(prompt_pwd) (set_color normal)
|
(prompt_pwd) (set_color normal)
|
||||||
case '*'
|
case '*'
|
||||||
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) \
|
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
|
||||||
(set_color bryellow) $last_pipestatus)
|
(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) \
|
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" \
|
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
|
||||||
$status_color $last_status (set_color normal)
|
(set_color normal)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
function fish_prompt --description 'Write out the prompt'
|
function fish_prompt --description 'Write out the prompt'
|
||||||
set -l last_pipestatus $pipestatus
|
set -l last_pipestatus $pipestatus
|
||||||
set -l last_status $status
|
|
||||||
|
|
||||||
if not set -q __fish_git_prompt_show_informative_status
|
if not set -q __fish_git_prompt_show_informative_status
|
||||||
set -g __fish_git_prompt_show_informative_status 1
|
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
|
set -g __fish_git_prompt_color_cleanstate green --bold
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set -q fish_color_status
|
||||||
|
or set -U fish_color_status red
|
||||||
|
|
||||||
set -l color_cwd
|
set -l color_cwd
|
||||||
set -l prefix
|
set -l prefix
|
||||||
set -l suffix
|
set -l suffix
|
||||||
|
@ -80,14 +82,9 @@ function fish_prompt --description 'Write out the prompt'
|
||||||
|
|
||||||
printf '%s ' (fish_vcs_prompt)
|
printf '%s ' (fish_vcs_prompt)
|
||||||
|
|
||||||
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color yellow) (set_color --bold yellow) $last_pipestatus)
|
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus)
|
||||||
echo -n "$pipestatus_string"
|
echo -n $pipestatus_string
|
||||||
|
|
||||||
if not test $last_status -eq 0
|
|
||||||
set_color $fish_color_error
|
|
||||||
echo -n "[$last_status] "
|
|
||||||
set_color normal
|
set_color normal
|
||||||
end
|
|
||||||
|
|
||||||
echo -n "$suffix "
|
echo -n "$suffix "
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue