fish-shell/share/tools/web_config/sample_prompts/classic_status.fish
Johannes Altmanninger 55bc6a27c6 Make prompts forward compatible with fish 3.1.2 by passing locally exported variable
Commit 5d135d555 (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.
2020-09-05 09:58:55 +02:00

29 lines
868 B
Fish

# name: Classic + Status
# author: David Frascone
function fish_prompt --description "Write out the prompt"
# Save our status
set -l last_pipestatus $pipestatus
set -lx __fish_last_status $status # Export for __fish_print_pipestatus.
set -l color_cwd
set -l suffix
if functions -q fish_is_root_user; and fish_is_root_user
if set -q fish_color_cwd_root
set color_cwd $fish_color_cwd_root
else
set color_cwd $fish_color_cwd
end
set suffix '#'
else
set color_cwd $fish_color_cwd
set suffix '>'
end
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) \
" "(__fish_print_pipestatus "[" "]" "|" (set_color $fish_color_status) (set_color --bold $fish_color_status) $last_pipestatus) \
(set_color normal) "$suffix "
end