mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Make prompts forward compatible with fish 3.1.2 by passing locally exported variable
Commit5d135d555
(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.
This commit is contained in:
parent
89724f9366
commit
55bc6a27c6
6 changed files with 12 additions and 13 deletions
|
@ -1,8 +1,7 @@
|
|||
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]
|
||||
if set -q __fish_last_status
|
||||
set last_status $__fish_last_status
|
||||
else
|
||||
set last_status $argv[-1] # default to $pipestatus[-1]
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
set -lx __fish_last_status $status # Export for __fish_print_pipestatus.
|
||||
set -l normal (set_color normal)
|
||||
|
||||
# Color the prompt differently when we're root
|
||||
|
@ -30,7 +30,7 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set bold_flag
|
||||
end
|
||||
set __fish_prompt_status_generation $status_generation
|
||||
set -l prompt_status (__fish_print_pipestatus $last_status "[" "]" "|" (set_color $fish_color_status) (set_color $bold_flag $fish_color_status) $last_pipestatus)
|
||||
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" (set_color $fish_color_status) (set_color $bold_flag $fish_color_status) $last_pipestatus)
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
function fish_prompt --description "Write out the prompt"
|
||||
# Save our status
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
set -lx __fish_last_status $status # Export for __fish_print_pipestatus.
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
|
@ -23,6 +23,6 @@ function fish_prompt --description "Write out the prompt"
|
|||
end
|
||||
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) \
|
||||
" "(__fish_print_pipestatus $last_status "[" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus) \
|
||||
" "(__fish_print_pipestatus "[" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus) \
|
||||
(set_color normal) "$suffix "
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
set -lx __fish_last_status $status # Export for __fish_print_pipestatus.
|
||||
set -l normal (set_color normal)
|
||||
|
||||
# Color the prompt differently when we're root
|
||||
|
@ -30,7 +30,7 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set bold_flag
|
||||
end
|
||||
set __fish_prompt_status_generation $status_generation
|
||||
set -l prompt_status (__fish_print_pipestatus $last_status "[" "]" "|" (set_color $fish_color_status) (set_color $bold_flag $fish_color_status) $last_pipestatus)
|
||||
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" (set_color $fish_color_status) (set_color $bold_flag $fish_color_status) $last_pipestatus)
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
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 -lx __fish_last_status $status # Export for __fish_print_pipestatus.
|
||||
|
||||
if functions -q fish_is_root_user; and fish_is_root_user
|
||||
printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
|
||||
|
@ -12,7 +12,7 @@ function fish_prompt --description 'Informative prompt'
|
|||
or set_color $fish_color_cwd) \
|
||||
(prompt_pwd) (set_color normal)
|
||||
else
|
||||
set -l pipestatus_string (__fish_print_pipestatus $last_status "[" "] " "|" (set_color $fish_color_status) \
|
||||
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 \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
set -lx __fish_last_status $status # Export for __fish_print_pipestatus.
|
||||
|
||||
if not set -q __fish_git_prompt_show_informative_status
|
||||
set -g __fish_git_prompt_show_informative_status 1
|
||||
|
@ -78,7 +78,7 @@ function fish_prompt --description 'Write out the prompt'
|
|||
|
||||
printf '%s ' (fish_vcs_prompt)
|
||||
|
||||
set -l pipestatus_string (__fish_print_pipestatus $last_status "[" "] " "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $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
|
||||
set_color normal
|
||||
|
||||
|
|
Loading…
Reference in a new issue