From d8f1a2a24f51010d2ee870395044fd1900689257 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 13 Dec 2025 15:11:46 +0100 Subject: [PATCH] Move sample_prompts/themes to share/ They are used by "fish_config" CLI too, so no need to make them private to webconfig. Putting them at top-level seems simpler overall. --- cmake/Install.cmake | 4 +- contrib/debian/copyright | 4 +- share/functions/__fish_theme_cat.fish | 2 +- share/functions/__fish_theme_paths.fish | 2 +- share/functions/fish_config.fish | 2 +- .../sample_prompts => prompts}/acidhub.fish | 0 .../sample_prompts => prompts}/arrow.fish | 0 .../sample_prompts => prompts}/astronaut.fish | 0 .../sample_prompts => prompts}/default.fish | 0 .../sample_prompts => prompts}/disco.fish | 0 .../informative.fish | 0 .../informative_vcs.fish | 0 .../minimalist.fish | 0 .../sample_prompts => prompts}/nim.fish | 0 .../pythonista.fish | 0 .../sample_prompts => prompts}/scales.fish | 0 .../sample_prompts => prompts}/simple.fish | 0 .../sample_prompts => prompts}/terlar.fish | 0 .../web_config => }/themes/ayu-dark.theme | 0 .../web_config => }/themes/ayu-light.theme | 0 .../web_config => }/themes/ayu-mirage.theme | 0 .../themes/base16-default-dark.theme | 0 .../themes/base16-default-light.theme | 0 .../themes/base16-eighties.theme | 0 .../web_config => }/themes/bay-cruise.theme | 0 .../web_config => }/themes/coolbeans.theme | 0 .../web_config => }/themes/default-dark.theme | 0 .../themes/default-light.theme | 0 .../web_config => }/themes/default.theme | 0 .../web_config => }/themes/dracula.theme | 0 .../web_config => }/themes/fairground.theme | 0 .../web_config => }/themes/just-a-touch.theme | 0 .../{tools/web_config => }/themes/lava.theme | 0 .../web_config => }/themes/mono-lace.theme | 0 .../web_config => }/themes/mono-smoke.theme | 0 .../{tools/web_config => }/themes/none.theme | 0 .../{tools/web_config => }/themes/nord.theme | 0 .../web_config => }/themes/old-school.theme | 0 .../web_config => }/themes/seaweed.theme | 0 .../web_config => }/themes/snow-day.theme | 0 .../themes/solarized-dark.theme | 0 .../themes/solarized-light.theme | 0 .../themes/tomorrow-night-bright.theme | 0 .../themes/tomorrow-night.theme | 0 .../web_config => }/themes/tomorrow.theme | 0 share/tools/web_config/webconfig.py | 65 ++++++++++++------- tests/checks/fish_config.fish | 4 +- tests/checks/prompt.fish | 16 ++--- 48 files changed, 57 insertions(+), 42 deletions(-) rename share/{tools/web_config/sample_prompts => prompts}/acidhub.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/arrow.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/astronaut.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/default.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/disco.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/informative.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/informative_vcs.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/minimalist.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/nim.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/pythonista.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/scales.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/simple.fish (100%) rename share/{tools/web_config/sample_prompts => prompts}/terlar.fish (100%) rename share/{tools/web_config => }/themes/ayu-dark.theme (100%) rename share/{tools/web_config => }/themes/ayu-light.theme (100%) rename share/{tools/web_config => }/themes/ayu-mirage.theme (100%) rename share/{tools/web_config => }/themes/base16-default-dark.theme (100%) rename share/{tools/web_config => }/themes/base16-default-light.theme (100%) rename share/{tools/web_config => }/themes/base16-eighties.theme (100%) rename share/{tools/web_config => }/themes/bay-cruise.theme (100%) rename share/{tools/web_config => }/themes/coolbeans.theme (100%) rename share/{tools/web_config => }/themes/default-dark.theme (100%) rename share/{tools/web_config => }/themes/default-light.theme (100%) rename share/{tools/web_config => }/themes/default.theme (100%) rename share/{tools/web_config => }/themes/dracula.theme (100%) rename share/{tools/web_config => }/themes/fairground.theme (100%) rename share/{tools/web_config => }/themes/just-a-touch.theme (100%) rename share/{tools/web_config => }/themes/lava.theme (100%) rename share/{tools/web_config => }/themes/mono-lace.theme (100%) rename share/{tools/web_config => }/themes/mono-smoke.theme (100%) rename share/{tools/web_config => }/themes/none.theme (100%) rename share/{tools/web_config => }/themes/nord.theme (100%) rename share/{tools/web_config => }/themes/old-school.theme (100%) rename share/{tools/web_config => }/themes/seaweed.theme (100%) rename share/{tools/web_config => }/themes/snow-day.theme (100%) rename share/{tools/web_config => }/themes/solarized-dark.theme (100%) rename share/{tools/web_config => }/themes/solarized-light.theme (100%) rename share/{tools/web_config => }/themes/tomorrow-night-bright.theme (100%) rename share/{tools/web_config => }/themes/tomorrow-night.theme (100%) rename share/{tools/web_config => }/themes/tomorrow.theme (100%) diff --git a/cmake/Install.cmake b/cmake/Install.cmake index 8e9f96ccf..cedb9ef97 100644 --- a/cmake/Install.cmake +++ b/cmake/Install.cmake @@ -95,8 +95,8 @@ fish_create_dirs(${rel_datadir}/fish ${rel_datadir}/fish/completions ${rel_datadir}/fish/man/man1 ${rel_datadir}/fish/tools ${rel_datadir}/fish/tools/web_config ${rel_datadir}/fish/tools/web_config/js - ${rel_datadir}/fish/tools/web_config/sample_prompts - ${rel_datadir}/fish/tools/web_config/themes + ${rel_datadir}/fish/prompts + ${rel_datadir}/fish/themes ) configure_file(share/__fish_build_paths.fish.in share/__fish_build_paths.fish) diff --git a/contrib/debian/copyright b/contrib/debian/copyright index cbb7b941d..f6915912e 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -17,11 +17,11 @@ Files: share/tools/web_config/js/alpine.js Copyright: 2019-2021 Caleb Porzio and contributors License: MIT -Files: share/tools/web_config/themes/Dracula.theme +Files: share/themes/Dracula.theme Copyright: 2018 Dracula Team License: MIT -Files: share/tools/web_config/themes/Nord.theme +Files: share/themes/Nord.theme Copyright: 2016-2024 Sven Greb License: MIT diff --git a/share/functions/__fish_theme_cat.fish b/share/functions/__fish_theme_cat.fish index 9451b1611..237b10bb8 100644 --- a/share/functions/__fish_theme_cat.fish +++ b/share/functions/__fish_theme_cat.fish @@ -3,7 +3,7 @@ function __fish_theme_cat -a theme_name set -l theme_path (__fish_theme_paths $theme_name)[1] if not set -q theme_path[1] echo >&2 "No such theme: $theme_name" - echo >&2 Searched (__fish_theme_dir) "and `status list-files tools/web_config/themes`" + echo >&2 Searched (__fish_theme_dir) "and `status list-files themes`" return 1 end __fish_data_with_file $theme_path cat diff --git a/share/functions/__fish_theme_paths.fish b/share/functions/__fish_theme_paths.fish index a72c8d2d9..b172c78ad 100644 --- a/share/functions/__fish_theme_paths.fish +++ b/share/functions/__fish_theme_paths.fish @@ -1,5 +1,5 @@ # localization: skip(private) function __fish_theme_paths __fish_config_files --user-dir=(__fish_theme_dir) \ - tools/web_config/themes .theme $argv + themes .theme $argv end diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish index 5888745c1..21856f0e9 100644 --- a/share/functions/fish_config.fish +++ b/share/functions/fish_config.fish @@ -203,7 +203,7 @@ end function __fish_config_list_prompts set -lx dir - set -l prompt_paths (__fish_config_files tools/web_config/sample_prompts .fish $argv) + 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..] diff --git a/share/tools/web_config/sample_prompts/acidhub.fish b/share/prompts/acidhub.fish similarity index 100% rename from share/tools/web_config/sample_prompts/acidhub.fish rename to share/prompts/acidhub.fish diff --git a/share/tools/web_config/sample_prompts/arrow.fish b/share/prompts/arrow.fish similarity index 100% rename from share/tools/web_config/sample_prompts/arrow.fish rename to share/prompts/arrow.fish diff --git a/share/tools/web_config/sample_prompts/astronaut.fish b/share/prompts/astronaut.fish similarity index 100% rename from share/tools/web_config/sample_prompts/astronaut.fish rename to share/prompts/astronaut.fish diff --git a/share/tools/web_config/sample_prompts/default.fish b/share/prompts/default.fish similarity index 100% rename from share/tools/web_config/sample_prompts/default.fish rename to share/prompts/default.fish diff --git a/share/tools/web_config/sample_prompts/disco.fish b/share/prompts/disco.fish similarity index 100% rename from share/tools/web_config/sample_prompts/disco.fish rename to share/prompts/disco.fish diff --git a/share/tools/web_config/sample_prompts/informative.fish b/share/prompts/informative.fish similarity index 100% rename from share/tools/web_config/sample_prompts/informative.fish rename to share/prompts/informative.fish diff --git a/share/tools/web_config/sample_prompts/informative_vcs.fish b/share/prompts/informative_vcs.fish similarity index 100% rename from share/tools/web_config/sample_prompts/informative_vcs.fish rename to share/prompts/informative_vcs.fish diff --git a/share/tools/web_config/sample_prompts/minimalist.fish b/share/prompts/minimalist.fish similarity index 100% rename from share/tools/web_config/sample_prompts/minimalist.fish rename to share/prompts/minimalist.fish diff --git a/share/tools/web_config/sample_prompts/nim.fish b/share/prompts/nim.fish similarity index 100% rename from share/tools/web_config/sample_prompts/nim.fish rename to share/prompts/nim.fish diff --git a/share/tools/web_config/sample_prompts/pythonista.fish b/share/prompts/pythonista.fish similarity index 100% rename from share/tools/web_config/sample_prompts/pythonista.fish rename to share/prompts/pythonista.fish diff --git a/share/tools/web_config/sample_prompts/scales.fish b/share/prompts/scales.fish similarity index 100% rename from share/tools/web_config/sample_prompts/scales.fish rename to share/prompts/scales.fish diff --git a/share/tools/web_config/sample_prompts/simple.fish b/share/prompts/simple.fish similarity index 100% rename from share/tools/web_config/sample_prompts/simple.fish rename to share/prompts/simple.fish diff --git a/share/tools/web_config/sample_prompts/terlar.fish b/share/prompts/terlar.fish similarity index 100% rename from share/tools/web_config/sample_prompts/terlar.fish rename to share/prompts/terlar.fish diff --git a/share/tools/web_config/themes/ayu-dark.theme b/share/themes/ayu-dark.theme similarity index 100% rename from share/tools/web_config/themes/ayu-dark.theme rename to share/themes/ayu-dark.theme diff --git a/share/tools/web_config/themes/ayu-light.theme b/share/themes/ayu-light.theme similarity index 100% rename from share/tools/web_config/themes/ayu-light.theme rename to share/themes/ayu-light.theme diff --git a/share/tools/web_config/themes/ayu-mirage.theme b/share/themes/ayu-mirage.theme similarity index 100% rename from share/tools/web_config/themes/ayu-mirage.theme rename to share/themes/ayu-mirage.theme diff --git a/share/tools/web_config/themes/base16-default-dark.theme b/share/themes/base16-default-dark.theme similarity index 100% rename from share/tools/web_config/themes/base16-default-dark.theme rename to share/themes/base16-default-dark.theme diff --git a/share/tools/web_config/themes/base16-default-light.theme b/share/themes/base16-default-light.theme similarity index 100% rename from share/tools/web_config/themes/base16-default-light.theme rename to share/themes/base16-default-light.theme diff --git a/share/tools/web_config/themes/base16-eighties.theme b/share/themes/base16-eighties.theme similarity index 100% rename from share/tools/web_config/themes/base16-eighties.theme rename to share/themes/base16-eighties.theme diff --git a/share/tools/web_config/themes/bay-cruise.theme b/share/themes/bay-cruise.theme similarity index 100% rename from share/tools/web_config/themes/bay-cruise.theme rename to share/themes/bay-cruise.theme diff --git a/share/tools/web_config/themes/coolbeans.theme b/share/themes/coolbeans.theme similarity index 100% rename from share/tools/web_config/themes/coolbeans.theme rename to share/themes/coolbeans.theme diff --git a/share/tools/web_config/themes/default-dark.theme b/share/themes/default-dark.theme similarity index 100% rename from share/tools/web_config/themes/default-dark.theme rename to share/themes/default-dark.theme diff --git a/share/tools/web_config/themes/default-light.theme b/share/themes/default-light.theme similarity index 100% rename from share/tools/web_config/themes/default-light.theme rename to share/themes/default-light.theme diff --git a/share/tools/web_config/themes/default.theme b/share/themes/default.theme similarity index 100% rename from share/tools/web_config/themes/default.theme rename to share/themes/default.theme diff --git a/share/tools/web_config/themes/dracula.theme b/share/themes/dracula.theme similarity index 100% rename from share/tools/web_config/themes/dracula.theme rename to share/themes/dracula.theme diff --git a/share/tools/web_config/themes/fairground.theme b/share/themes/fairground.theme similarity index 100% rename from share/tools/web_config/themes/fairground.theme rename to share/themes/fairground.theme diff --git a/share/tools/web_config/themes/just-a-touch.theme b/share/themes/just-a-touch.theme similarity index 100% rename from share/tools/web_config/themes/just-a-touch.theme rename to share/themes/just-a-touch.theme diff --git a/share/tools/web_config/themes/lava.theme b/share/themes/lava.theme similarity index 100% rename from share/tools/web_config/themes/lava.theme rename to share/themes/lava.theme diff --git a/share/tools/web_config/themes/mono-lace.theme b/share/themes/mono-lace.theme similarity index 100% rename from share/tools/web_config/themes/mono-lace.theme rename to share/themes/mono-lace.theme diff --git a/share/tools/web_config/themes/mono-smoke.theme b/share/themes/mono-smoke.theme similarity index 100% rename from share/tools/web_config/themes/mono-smoke.theme rename to share/themes/mono-smoke.theme diff --git a/share/tools/web_config/themes/none.theme b/share/themes/none.theme similarity index 100% rename from share/tools/web_config/themes/none.theme rename to share/themes/none.theme diff --git a/share/tools/web_config/themes/nord.theme b/share/themes/nord.theme similarity index 100% rename from share/tools/web_config/themes/nord.theme rename to share/themes/nord.theme diff --git a/share/tools/web_config/themes/old-school.theme b/share/themes/old-school.theme similarity index 100% rename from share/tools/web_config/themes/old-school.theme rename to share/themes/old-school.theme diff --git a/share/tools/web_config/themes/seaweed.theme b/share/themes/seaweed.theme similarity index 100% rename from share/tools/web_config/themes/seaweed.theme rename to share/themes/seaweed.theme diff --git a/share/tools/web_config/themes/snow-day.theme b/share/themes/snow-day.theme similarity index 100% rename from share/tools/web_config/themes/snow-day.theme rename to share/themes/snow-day.theme diff --git a/share/tools/web_config/themes/solarized-dark.theme b/share/themes/solarized-dark.theme similarity index 100% rename from share/tools/web_config/themes/solarized-dark.theme rename to share/themes/solarized-dark.theme diff --git a/share/tools/web_config/themes/solarized-light.theme b/share/themes/solarized-light.theme similarity index 100% rename from share/tools/web_config/themes/solarized-light.theme rename to share/themes/solarized-light.theme diff --git a/share/tools/web_config/themes/tomorrow-night-bright.theme b/share/themes/tomorrow-night-bright.theme similarity index 100% rename from share/tools/web_config/themes/tomorrow-night-bright.theme rename to share/themes/tomorrow-night-bright.theme diff --git a/share/tools/web_config/themes/tomorrow-night.theme b/share/themes/tomorrow-night.theme similarity index 100% rename from share/tools/web_config/themes/tomorrow-night.theme rename to share/themes/tomorrow-night.theme diff --git a/share/tools/web_config/themes/tomorrow.theme b/share/themes/tomorrow.theme similarity index 100% rename from share/tools/web_config/themes/tomorrow.theme rename to share/themes/tomorrow.theme diff --git a/share/tools/web_config/webconfig.py b/share/tools/web_config/webconfig.py index d09a4f531..ad8b96820 100755 --- a/share/tools/web_config/webconfig.py +++ b/share/tools/web_config/webconfig.py @@ -97,7 +97,7 @@ def is_chromeos_garcon(): return False -def run_fish_cmd(text): +def run_fish_cmd(text, strict=False): print("$ " + text) p = subprocess.Popen( [FISH_BIN_PATH], @@ -108,9 +108,27 @@ def run_fish_cmd(text): out, err = p.communicate(text.encode("utf-8")) out = out.decode("utf-8", "replace") err = err.decode("utf-8", "replace") + if strict: + assert err == "" + # TODO use check_output() + return out return out, err +def list_embedded_files(path, suffix): + return [ + path + for path in run_fish_cmd( + "status list-files " + escape_fish_cmd(path), strict=True + ).splitlines() + if path.endswith(suffix) + ] + + +def get_embedded_file(path): + return run_fish_cmd("status get-file " + escape_fish_cmd(path), strict=True) + + def escape_fish_cmd(text): # Replace one backslash with two, and single quotes with backslash-quote escaped = text.replace("\\", "\\\\").replace("'", "\\'") @@ -764,8 +782,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): if not path: out, err = run_fish_cmd("fish_config theme dump") else: - with open(path) as f: - out = f.read() + out = get_embedded_file(path) info = {} colors = [] @@ -1018,32 +1035,30 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): def read_one_sample_prompt(self, path): try: - with open(path, "rb") as fd: - extras_dict = {} - # Read one sample prompt from fd - function_lines = [] - parsing_hashes = True - unicode_lines = (line.decode("utf-8") for line in fd) - for line in unicode_lines: - # Parse hashes until parse_one_sample_prompt_hash return - # False. - if parsing_hashes: - parsing_hashes = self.parse_one_sample_prompt_hash( - line, extras_dict - ) - # Maybe not we're not parsing hashes, or maybe we already - # were not. - if not parsing_hashes: - function_lines.append(line) - func = "".join(function_lines).strip() - result = self.do_get_sample_prompt(func, extras_dict) - return result + extras_dict = {} + # Read one sample prompt from out + function_lines = [] + parsing_hashes = True + for line in get_embedded_file(path).splitlines(keepends=True): + # Parse hashes until parse_one_sample_prompt_hash return + # False. + if parsing_hashes: + parsing_hashes = self.parse_one_sample_prompt_hash( + line, extras_dict + ) + # Maybe not we're not parsing hashes, or maybe we already + # were not. + if not parsing_hashes: + function_lines.append(line) + func = "".join(function_lines).strip() + result = self.do_get_sample_prompt(func, extras_dict) + return result except IOError: # Ignore unreadable files, etc. return None def do_get_sample_prompts_list(self): - paths = sorted(glob.iglob("sample_prompts/*.fish")) + paths = list_embedded_files("prompts", ".fish") result = [] try: pool = multiprocessing.pool.ThreadPool(processes=8) @@ -1120,7 +1135,7 @@ class FishConfigHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): else os.path.expanduser("~") ) paths = list(glob.iglob(os.path.join(confighome, "fish", "themes/*.theme"))) - paths.extend(list(glob.iglob("themes/*.theme"))) + paths.extend(list_embedded_files("themes", ".theme")) paths.sort(key=str.casefold) for p in paths: diff --git a/tests/checks/fish_config.fish b/tests/checks/fish_config.fish index 2afca77ee..38ef3aae3 100644 --- a/tests/checks/fish_config.fish +++ b/tests/checks/fish_config.fish @@ -107,7 +107,7 @@ type fish_mode_prompt fish_config theme choose non-existent-theme1 # CHECKERR: No such theme: non-existent-theme1 -# CHECKERR: Searched {{/\S* (/\S*|and `status list-files tools/web_config/themes`)}} +# CHECKERR: Searched {{/\S* (/\S*|and `status list-files themes`)}} # This still demos the current theme. fish_config theme show non-existent-theme2 @@ -156,7 +156,7 @@ fish_config theme show | grep -E '[^-]default|base16-default-dark|custom-from-us # CHECK: {{.*}}default{{\x1b\[m}} # Override a default theme with different colors. -__fish_data_with_file tools/web_config/themes/none.theme \ +__fish_data_with_file themes/none.theme \ cat >$__fish_config_dir/themes/default.theme fish_config theme show | grep -E '[^-]default|base16-default-dark' -A1 # CHECK: {{\x1b\[m}}{{\x1b\[4m}}default{{\x1b\[m}} diff --git a/tests/checks/prompt.fish b/tests/checks/prompt.fish index a600dfff0..65aea0620 100644 --- a/tests/checks/prompt.fish +++ b/tests/checks/prompt.fish @@ -3,14 +3,14 @@ prompt_pwd -d 1 /foo/bar/baz # CHECK: /f/b/baz -prompt_pwd /usr/share/fish/tools/web_config/sample_prompts -# CHECK: /u/s/f/t/w/sample_prompts +prompt_pwd /usr/share/fish/prompts +# CHECK: /u/s/f/prompts -prompt_pwd -D 2 /usr/share/fish/tools/web_config/sample_prompts -# CHECK: /u/s/f/t/web_config/sample_prompts +prompt_pwd -D 2 /usr/share/fish/prompts +# CHECK: /u/s/fish/prompts -prompt_pwd -D 0 /usr/share/fish/tools/web_config/sample_prompts -# CHECK: /u/s/f/t/w/s +prompt_pwd -D 0 /usr/share/fish/prompts +# CHECK: /u/s/f/p -prompt_pwd -d1 -D 3 /usr/share/fish/tools/web_config/-sample_prompts -# CHECK: /u/s/f/tools/web_config/-sample_prompts +prompt_pwd -d1 -D 3 /usr/local/share/fish/prompts +# CHECK: /u/l/share/fish/prompts