Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(prompts): add fish_config_dir/prompts to prompts list#12258

Open
l4zygreed wants to merge 4 commits intofish-shell:masterfrom
l4zygreed:feat/custom_prompts
Open

feat(prompts): add fish_config_dir/prompts to prompts list#12258
l4zygreed wants to merge 4 commits intofish-shell:masterfrom
l4zygreed:feat/custom_prompts

Conversation

@l4zygreed
Copy link

Description

added fish_config_dir/prompts folder in __fish_config_list_prompts function in fish_config script so it can now also pick custom prompts from prompts folder inside user config dir.
Also updated fish_config.rst file. But it probably should be reworded because I simply copied themes section and replaced theme with prompt. Any suggestions about this?

Fixes issue #2577

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@l4zygreed l4zygreed force-pushed the feat/custom_prompts branch from 69cf4c0 to 5c55215 Compare January 3, 2026 09:09
@krobelus krobelus added this to the fish 4.4 milestone Jan 4, 2026
function __fish_config_list_prompts
set -lx dir
set -l prompt_paths (__fish_config_files prompts .fish $argv)
set -l prompt_paths (__fish_config_files --user-dir=(__fish_prompt_dir) prompts .fish $argv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this requires some other changes.
I started (and added a test), see the diff below.

But we also want to change the webconfig accordingly, see
do_get_sample_prompts_list() in share/tools/web_config/webconfig.py.
Currently it only supports the sample prompts.
User prompts should shadow sample prompts of the same name.
I guess this issue is not technically a blocker but now's the best time to do that, to avoid introducing a surprising inconsistency.

diff --git a/doc_src/cmds/fish_config.rst b/doc_src/cmds/fish_config.rst
index 17ec564d39..fa915312c2 100644
--- a/doc_src/cmds/fish_config.rst
+++ b/doc_src/cmds/fish_config.rst
@@ -51,10 +51,19 @@
 
 .. _fish-config-theme-files:
 
+Prompt Files
+------------
+
+``fish_config prompt`` and the prompt selector in the web config tool load prompts from fish files.
+These are stored in the fish configuration directory, typically ``~/.config/fish/prompts``, with a .fish ending.
+
+You can add your own prompt by adding a file in that directory.
+
 Theme Files
 -----------
 
-``fish_config theme`` and the theme selector in the web config tool load their themes from theme files. These are stored in the fish configuration directory, typically ``~/.config/fish/themes``, with a .theme ending.
+``fish_config theme`` and the theme selector in the web config tool load their themes from theme files.
+These are stored in the fish configuration directory, typically ``~/.config/fish/themes``, with a .theme ending.
 
 You can add your own theme by adding a file in that directory.
 
diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish
index b0b0c0221e..5a7fc456df 100644
--- a/share/functions/fish_config.fish
+++ b/share/functions/fish_config.fish
@@ -114,13 +114,13 @@
                         return 1
                     end
 
-                    set -l prompt_path (__fish_config_list_prompts $argv[1])
-                    if not set -q prompt_path[1]
+                    set -l prompt_paths (__fish_config_list_prompts $argv[1])
+                    if not set -q prompt_paths[1]
                         echo "No such prompt: '$argv[1]'" >&2
                         return 1
                     end
                     __fish_config_prompt_reset
-                    __fish_config_with_file $prompt_path source
+                    __fish_config_with_file $prompt_paths[1] source
                     if not functions -q fish_mode_prompt
                         status get-file functions/fish_mode_prompt.fish | source
                     end
@@ -136,13 +136,13 @@
                     __fish_backup_config_files functions/{fish_prompt,fish_right_prompt,fish_mode_prompt}.fish
 
                     if set -q argv[1]
-                        set -l prompt_path (__fish_config_list_prompts $argv[1])
-                        if not set -q prompt_path[1]
+                        set -l prompt_paths (__fish_config_list_prompts $argv[1])
+                        if not set -q prompt_paths[1]
                             echo "No such prompt: '$argv[1]'" >&2
                             return 1
                         end
                         __fish_config_prompt_reset
-                        __fish_config_with_file $prompt_path source
+                        __fish_config_with_file $prompt_paths[1] source
                     end
 
                     funcsave fish_prompt
@@ -225,13 +225,7 @@
 end
 
 function __fish_config_list_prompts
-    set -lx dir
-    set -l prompt_paths (__fish_config_files prompts .fish $argv)
-    if [ (count $argv) = 1 ] && set -q prompt_paths[2]
-        echo >&2 "fish_config: internal error: multiple prompts matching '$argv' ??"
-        set --erase prompt_paths[2..]
-    end
-    string join \n -- $prompt_paths
+    __fish_config_files --user-dir=$__fish_config_dir/prompts prompts .fish $argv
 end
 
 function __fish_config_theme_choose_bad_color_theme -a theme_name desired_color_theme source
diff --git a/tests/checks/fish_config.fish b/tests/checks/fish_config.fish
index c42cc8136c..0fa9f25d9f 100644
--- a/tests/checks/fish_config.fish
+++ b/tests/checks/fish_config.fish
@@ -12,13 +12,23 @@
 
 fish_config prompt show non-existent-prompt
 
+mkdir $__fish_config_dir/prompts
+echo 'function fish_prompt; echo acidhub-overrridden; end' >$__fish_config_dir/prompts/acidhub.fish
+fish_config prompt choose acidhub
+type fish_prompt
+# CHECK: fish_prompt is a function with definition
+# CHECK: # Defined in {{.*}}/xdg_config_home/fish/prompts/acidhub.fish @ line 1
+# CHECK: function fish_prompt
+# CHECK:  echo acidhub-overrridden;
+# CHECK: end
+
 fish_config prompt show default
 # CHECK: {{\x1b\[4m}}default{{\x1b\[m}}
 # CHECK: {{.*}}@{{.*}}>{{.*}}
 
 type fish_mode_prompt
 # CHECK: fish_mode_prompt is a function with definition
-# CHECK: # Defined in {{.*}}functions/fish_mode_prompt.fish @ line 2
+# CHECK: # Defined via `source`
 # CHECK: function fish_mode_prompt --description 'Displays the current mode'
 # CHECK:     # {{.*}}
 # CHECK:     fish_default_mode_prompt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I add this in separate commit or you can add this? 🤔

@krobelus
Copy link
Contributor

krobelus commented Jan 5, 2026 via email

@l4zygreed l4zygreed force-pushed the feat/custom_prompts branch from 65f9eff to ae4f0ac Compare January 6, 2026 00:29
@l4zygreed
Copy link
Author

l4zygreed commented Jan 6, 2026

instead of "fish_config prompt choose foo" can't you run "source ~/.config/fish/prompts/foo.fish" ?

Yeah, I can, basically right now I have theme installed as fish_prompt.fish file in conf.d directory.

But I always thought that it would be nice to have multiple prompts in some directory and ability to freely switch between them. So if personal themes can be added via fish_config why prompts cant? 🤔

Modified webconfig.py, added few functions to list and read local prompts. And removed shadowed filenames from embedded list as requested.

But seems like have it have issue if filename is different but # name: Name comment in file is the same as in embedded files. Seems like frontend error. Should I also make some fix for that? 🤔

@l4zygreed
Copy link
Author

probably fixed frontend? replaced key from p.name to $id(p). Locally fixed page render in case when prompts have same name defined in comment line. Doesn't seems like key used elsewhere so probably change should be fine? Please check it.

@l4zygreed l4zygreed requested a review from krobelus January 6, 2026 05:54
@krobelus
Copy link
Contributor

krobelus commented Jan 6, 2026

But I always thought that it would be nice to have multiple prompts in some directory and ability to freely switch between them.

You already can, using source path/to/prompt.fish

Prompt Files
------------

``fish_config prompt`` and the theme selector in the web config tool load their themes from fish files. These are stored in the fish configuration directory, typically ``~/.config/fish/prompts``, with a .fish ending.
Copy link
Contributor

@krobelus krobelus Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already can, using source path/to/prompt.fish

Ok looking at share/functions/fish_config.fish,
fish_config prompt choose also resets
right prompt / mode prompt to the defaults,
so I guess that can be more convenient..
and it's not only useful to the future group of people using the webconfig and adding custom prompts.

So I guess that's fine, if only to give people a more standard structure for their prompts..

@@ -0,0 +1,4 @@
# localization: skip(private)
function __fish_prompt_dir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a separate function file is overkill, since this is only used once;
please also incorporate the changes I sketches, so "fish_config prompt choose is not broken.
For example the fix to __fish_config_list_prompts definitely belongs in the same commit that allows multiple prompt dirs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a separate function file is overkill

I've just copied how it's done for theme 😬

Copy link
Contributor

@krobelus krobelus Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm we might want to reuse this function for telling webconfig where to look for prompts, instead of duplicating this info in webconfig.py.
Would be great to have a single source of truth for that.
I wonder what's the simplest approach. Maybe we should have a function that lists all paths to prompts (except the shadowed ones). Relative ones for embedded ones I guess. Or do what __fish_theme_export_for_webconfig does, so webconfig only needs to invoke fish once to get all the prompts.

I'm still not entirely sure if we should have the prompt/theme user config directories in webconfig.

I also wonder if anyone actually uses fish_config prompt. The alternative would be telling users to run status get-file prompt/foo.fish | source instead which is uglier and might leave stale right prompt / mode prompt, but that can be fixed in obvious ways (e.g. with session restart) and it's much less magic

Copy link
Author

@l4zygreed l4zygreed Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if anyone actually uses fish_config prompt

Probably not
(I mean, why would they use it if there are only embedded prompts there? (except they want to use one of them) 🤔)
I guest most people use oh-my-fish theme selector or install them manually or with fisher or alternative package management scripts (which are basically putting fish_prompt.fish, etc. files into conf.d directory), like I do
so for switching themes I need to uninstall current one and install the one I want 🙃

I think that passing themes/prompts lists on server start is not very good idea, because for updating themes list they would need to restart whole server, while now they can just reload the page. (Probably will not be a huge issue, but anyway...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example the fix to __fish_config_list_prompts definitely belongs in the same commit that allows multiple prompt dirs

You want me to rebase PR? No problem, but I guess it's better for me to do it after "everything is fixed/resolved" I guess 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless there are specific questions, it's better to clean up history first, to help the few reviewers.

If we take this PR that would also imply /etc/fish/prompts etc. Need to be conscious about what we want; I guess it's fine to add

# remove shadowed themes from embedded_paths list
local_paths_names = {Path(p).name for p in local_paths}
embedded_paths = [
e for e in embedded_paths if Path(e).name not in local_paths_names
Copy link
Contributor

@krobelus krobelus Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that a future change wants to also add support for /etc/fish/{prompts,themes} (#9456),
so we could already prepare for this by making a function that takes a list of directory-lists.. but no need

@l4zygreed l4zygreed force-pushed the feat/custom_prompts branch 2 times, most recently from 0b75783 to 5711a59 Compare January 27, 2026 01:35
@l4zygreed l4zygreed requested a review from krobelus February 3, 2026 10:34
@zanchey zanchey modified the milestones: fish 4.4, fish-future Feb 8, 2026
@l4zygreed
Copy link
Author

rebased PR
idk if we need commit that fixes broken template since we shadow embedded themes
(but still may be duplicates in user folder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants