feat(prompts): add fish_config_dir/prompts to prompts list#12258
feat(prompts): add fish_config_dir/prompts to prompts list#12258l4zygreed wants to merge 4 commits intofish-shell:masterfrom
Conversation
69cf4c0 to
5c55215
Compare
share/functions/fish_config.fish
Outdated
| 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) |
There was a problem hiding this comment.
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_promptThere was a problem hiding this comment.
should I add this in separate commit or you can add this? 🤔
|
In the discussion in
#9456 (comment),
I found that maybe we don't need/want webconfig to respect the ~/.config/fish/{prompts,themes}.
So I think I'm good without that.
But actually, I don't really see value added by this PR.
instead of "fish_config prompt choose foo" can't you run "source ~/.config/fish/prompts/foo.fish" ?
(In future theme files should allow the same thing.)
|
65f9eff to
ae4f0ac
Compare
Yeah, I can, basically right now I have theme installed as fish_prompt.fish file in 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 |
|
probably fixed frontend? replaced key from |
You already can, using |
doc_src/cmds/fish_config.rst
Outdated
| 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. |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
a separate function file is overkill
I've just copied how it's done for theme 😬
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
0b75783 to
5711a59
Compare
Identical names in prompts breaks template, because key is prompt.name; switched to $id ( https://alpinejs.dev/magics/id )
Otherwise expecting import error makes no sense because there is no import inside try block.
5711a59 to
f21d50c
Compare
|
rebased PR |
Description
added
fish_config_dir/promptsfolder in__fish_config_list_promptsfunction in fish_config script so it can now also pick custom prompts from prompts folder inside user config dir.Also updated
fish_config.rstfile. 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: