mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-25 14:51:15 -03:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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..]
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user