From a216cfdd2f7da0f6666fdb665f168f350becd847 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 13 Oct 2025 18:20:08 +0200 Subject: [PATCH] fish_{config,update_completions}: extract function for standalone builds --- .../functions/__fish_data_with_directory.fish | 30 ++++++++++++ share/functions/__fish_with_status.fish | 7 +++ share/functions/fish_config.fish | 32 ++----------- share/functions/fish_update_completions.fish | 46 ++++++++----------- 4 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 share/functions/__fish_data_with_directory.fish create mode 100644 share/functions/__fish_with_status.fish diff --git a/share/functions/__fish_data_with_directory.fish b/share/functions/__fish_data_with_directory.fish new file mode 100644 index 000000000..d87c86808 --- /dev/null +++ b/share/functions/__fish_data_with_directory.fish @@ -0,0 +1,30 @@ +# localization: skip(private) +function __fish_data_with_directory + set -l relative_directory $argv[1] + set -l file_regex $argv[2] + set -l cmd $argv[3..] + set -l temp + set -l directory_ref + if set -q __fish_data_dir[1] + set directory_ref $__fish_data_dir/$relative_directory + else + set temp (__fish_mktemp_relative -d fish-data) + if set -l paths (status list-files $relative_directory | + string match -r \ + "^$(string escape --style=regex $relative_directory)/(?:$file_regex)\$") + mkdir -p -- $temp/(string join \n $paths | path dirname | path sort -u) + or return + for path in $paths + status get-file $path >$temp/$path + or return + end + end + set directory_ref $temp/$relative_directory + end + $cmd $directory_ref + set -l saved_status $status + if set -q temp[1] + command rm -r $temp + end + return $saved_status +end diff --git a/share/functions/__fish_with_status.fish b/share/functions/__fish_with_status.fish new file mode 100644 index 000000000..7451b74a1 --- /dev/null +++ b/share/functions/__fish_with_status.fish @@ -0,0 +1,7 @@ +# localization: skip(private) +function __fish_with_status + set -l saved_status $status + $argv + or return + return $saved_status +end diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish index 165ac03bd..94fd92de4 100644 --- a/share/functions/fish_config.fish +++ b/share/functions/fish_config.fish @@ -20,36 +20,14 @@ function fish_config --description "Launch fish's web based configuration" set -l fish_path (status fish-path) and set __fish_bin_dir (path dirname -- $fish_path) if set -l python (__fish_anypython) - set -l mainfile $__fish_data_dir/tools/web_config/webconfig.py - set -l temp - if not path is -- $mainfile - if not status list-files tools/web_config &>/dev/null - echo "Cannot find web configuration tool. Please check your fish installation." - return 1 - end - set temp (__fish_mktemp_relative -d fish_config) - or return - for dir in (status list-files tools/web_config | - path dirname | path sort -u) - mkdir -p $temp/$dir - or return - end - for file in (status list-files tools/web_config) - status get-file $file >$temp/$file - or return - end - set mainfile $temp/tools/web_config/webconfig.py - end - - $python "$mainfile" $argv - set -l saved_status $status - - if set -q temp[1] - command rm -r $temp + function __fish_config_webconfig -V python -a web_config + $python $web_config/webconfig.py end + __fish_data_with_directory tools/web_config '.*' __fish_config_webconfig + __fish_with_status functions --erase __fish_config_webconfig # If the execution of 'webconfig.py' fails, display python location and return. - if test $saved_status -ne 0 + or begin echo "Please check if Python has been installed successfully." echo "You can find the location of Python by executing the 'command -s $python' command." return 1 diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish index fe7612b96..e44936e05 100644 --- a/share/functions/fish_update_completions.fish +++ b/share/functions/fish_update_completions.fish @@ -1,35 +1,29 @@ function fish_update_completions --description "Update man-page based completions" - set -l script $__fish_data_dir/tools/create_manpage_completions.py set -l python (__fish_anypython) or begin printf "%s\n" (_ "python executable not found") >&2 return 1 end - set -l temp - if not test -e "$script" - if not status list-files tools/create_manpage_completions.py &>/dev/null - echo "Cannot find man page completion generator. Please check your fish installation." - return 1 - end - set temp (__fish_mktemp_relative -d fish_update_completions) - or return - for file in create_manpage_completions.py deroff.py - status get-file tools/$file >$temp/$file - or return - end - set script $temp/create_manpage_completions.py + function __fish_update_completions -V python + set -l user_args $argv[..-2] + set -l tools $argv[-1] + set -l update_args \ + # Don't write .pyc files. + -B \ + $tools/create_manpage_completions.py \ + # Use the manpath + --manpath \ + # Clean up old completions + --cleanup-in $__fish_user_data_dir/generated_completions \ + --cleanup-in $__fish_cache_dir/generated_completions \ + # Display progress + --progress \ + $user_args + $python $update_args end - - # Don't write .pyc files, use the manpath, clean up old completions - # display progress. - set -l update_args -B $script --manpath --cleanup-in $__fish_user_data_dir/generated_completions --cleanup-in $__fish_cache_dir/generated_completions --progress $argv - $python $update_args - set -l saved_status $status - - if set -q temp[1] - command rm -r $temp - end - - return $saved_status + __fish_data_with_directory tools \ + 'create_manpage_completions\.py|deroff\.py' \ + __fish_update_completions $argv + __fish_with_status functions --erase __fish_update_completions end