From 028e05fff1b5e7ce349069b377e1c57121fafcfd Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 13 Oct 2025 15:51:16 +0200 Subject: [PATCH] fish_config prompt choose: improve right prompt hack Rather than first sourcing the prompt, and then erasing the right prompt unless the prompt file defined the right prompt, start by erasing the right prompt. This is simpler (needs no conditional). --- share/functions/fish_config.fish | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish index 645c671a8..68c02050e 100644 --- a/share/functions/fish_config.fish +++ b/share/functions/fish_config.fish @@ -124,31 +124,24 @@ function fish_config --description "Launch fish's web based configuration" return 1 end - set -l have + set -l found false for f in $prompt_dir/$argv[1].fish if test -f $f + __fish_config_prompt_choose source $f - set have $f + set found true break end end - if not set -q have[1] + if not $found if status list-files tools/web_config/sample_prompts/$argv[1].fish &>/dev/null + __fish_config_prompt_choose status get-file tools/web_config/sample_prompts/$argv[1].fish | source - # HACK: `source` gives us a filename of "-", so we check manually if we had a right prompt - set have "" - status get-file tools/web_config/sample_prompts/$argv[1].fish | string match -q '*function fish_right_prompt*' - and set have - else echo "No such prompt: '$argv[1]'" >&2 return 1 end end - - # Erase the right prompt if it didn't have any. - if functions -q fish_right_prompt; and test (functions --details fish_right_prompt) != $have[1] - functions --erase fish_right_prompt - end case save read -P"Overwrite prompt? [y/N]" -l yesno if string match -riq 'y(es)?' -- $yesno @@ -398,3 +391,11 @@ function __fish_config_matching end string join \n $paths end + +function __fish_config_prompt_choose + if functions -q fish_right_prompt + # Unfortunately this disables autoloading for + # the rest of this session. + functions --erase fish_right_prompt + end +end