fish_config prompt choose: reset mode prompt and load it like right prompt

Fixes #11937
This commit is contained in:
Johannes Altmanninger
2025-10-14 00:49:47 +02:00
parent b44209e14e
commit d4837f9ef1
4 changed files with 56 additions and 21 deletions

View File

@@ -1,6 +1,26 @@
fish ?.?.? (released ???)
=========================
Notable improvements and fixes
------------------------------
Deprecations and removed features
---------------------------------
Interactive improvements
------------------------
- :doc:`fish_config prompt {choose,save} <cmds/fish_config>` have been taught to reset :doc:`fish_mode_prompt <cmds/fish_mode_prompt>` in addition to the other prompt functions (:issue:`11937`).
Scripting improvements
----------------------
Other improvements
------------------
For distributors
----------------
fish 4.1.3 (released ???)
=========================

View File

@@ -101,7 +101,11 @@ function fish_config --description "Launch fish's web based configuration"
echo "No such prompt: '$argv[1]'" >&2
return 1
end
__fish_data_with_file $prompt_path __fish_config_prompt_choose
__fish_config_prompt_reset
__fish_data_with_file $prompt_path source
if not functions -q fish_mode_prompt
__fish_data_with_file functions/fish_mode_prompt.fish source
end
case save
if begin
read -P"Overwrite prompt? [y/N]" -l yesno
@@ -113,7 +117,7 @@ function fish_config --description "Launch fish's web based configuration"
echo Overwriting
# Skip the cp if unnecessary,
# or we'd throw an error on a stock fish.
for function in fish_prompt fish_right_prompt
for function in fish_prompt fish_right_prompt fish_mode_prompt
path is $__fish_config_dir/functions/$function.fish
and cp $__fish_config_dir/functions/$function.fish{,.bak}
end
@@ -124,16 +128,22 @@ function fish_config --description "Launch fish's web based configuration"
echo "No such prompt: '$argv[1]'" >&2
return 1
end
__fish_data_with_file $prompt_path __fish_config_prompt_choose
__fish_config_prompt_reset
__fish_data_with_file $prompt_path source
end
funcsave fish_prompt
or return
if functions -q fish_right_prompt
funcsave fish_right_prompt
else
rm -f $__fish_config_dir/functions/fish_right_prompt.fish
for func in fish_right_prompt fish_mode_prompt
if functions -q $func
funcsave $func
else
rm -f $__fish_config_dir/functions/$func.fish
end
end
if not functions -q fish_mode_prompt
__fish_data_with_file functions/fish_mode_prompt.fish source
end
return
end
@@ -366,13 +376,14 @@ function __fish_config_matching
string join \n $paths
end
function __fish_config_prompt_choose
function __fish_config_prompt_reset
# Set the functions to empty so we empty the file
# if necessary.
function fish_prompt
end
if functions -q fish_right_prompt
functions --erase fish_right_prompt
for func in fish_right_prompt fish_mode_prompt
if functions -q $func
functions --erase $func
end
end
source $argv[1] # N.B We're passed either stdin or argv.
end

View File

@@ -79,9 +79,6 @@ function fish_prompt
_nim_prompt_wrapper $retc '' (date +%X)
# Vi-mode
# The default mode prompt would be prefixed, which ruins our alignment.
function fish_mode_prompt
end
if test "$fish_key_bindings" = fish_vi_key_bindings
or test "$fish_key_bindings" = fish_hybrid_key_bindings
@@ -138,3 +135,7 @@ function fish_prompt
echo -n '$ '
set_color normal
end
# The default mode prompt would be prefixed, which ruins our alignment.
function fish_mode_prompt
end

View File

@@ -37,7 +37,9 @@ grep '\S' $__fish_config_dir/functions/{fish_prompt,fish_right_prompt,fish_mode_
# CHECK: {{.*}}/functions/fish_right_prompt.fish:function fish_right_prompt
# CHECK: {{.*}}/functions/fish_right_prompt.fish: echo right-prompt
# CHECK: {{.*}}/functions/fish_right_prompt.fish:end
# CHECKERR: grep: {{.*}}/fish/functions/fish_mode_prompt.fish: No such file or directory
# CHECK: {{.*}}/functions/fish_mode_prompt.fish:function fish_mode_prompt
# CHECK: {{.*}}/functions/fish_mode_prompt.fish: echo mode-prompt
# CHECK: {{.*}}/functions/fish_mode_prompt.fish:end
echo yes | fish_config prompt save nim >/dev/null
grep -q nim@Hattori $__fish_config_dir/functions/fish_prompt.fish ||
@@ -45,7 +47,8 @@ echo 'failed to save prompt?'
cat $__fish_config_dir/functions/fish_right_prompt.fish
# CHECKERR: cat: {{.*}}/functions/fish_right_prompt.fish: No such file or directory
cat $__fish_config_dir/functions/fish_mode_prompt.fish
# CHECKERR: cat: {{.*}}/functions/fish_mode_prompt.fish: No such file or directory
# CHECK: function fish_mode_prompt
# CHECK: end
fish_config prompt choose nim
type fish_prompt fish_right_prompt fish_mode_prompt |
@@ -58,7 +61,7 @@ type fish_prompt fish_right_prompt fish_mode_prompt |
# CHECK: --
# CHECKERR: type: Could not find 'fish_right_prompt'
# CHECK: function fish_mode_prompt
# CHECK: echo mode-prompt
# CHECK:
fish_config prompt choose disco
type fish_prompt fish_right_prompt fish_mode_prompt |
@@ -72,8 +75,8 @@ grep -EA1 '^function.*|.*cksum$'
# CHECK: function fish_right_prompt
# CHECK: set -g __fish_git_prompt_showdirtystate 1
# CHECK: --
# CHECK: function fish_mode_prompt
# CHECK: echo mode-prompt
# CHECK: function fish_mode_prompt {{.*}}
# CHECK: # {{.*}}
fish_config prompt choose default
type fish_prompt fish_right_prompt fish_mode_prompt |
@@ -82,8 +85,8 @@ type fish_prompt fish_right_prompt fish_mode_prompt |
# CHECK: set -l last_pipestatus $pipestatus
# CHECKERR: type: Could not find 'fish_right_prompt'
# CHECK: --
# CHECK: function fish_mode_prompt
# CHECK: echo mode-prompt
# CHECK: function fish_mode_prompt {{.*}}
# CHECK: # {{.*}}
# This still demos the current theme.
fish_config theme show non-existent-theme