fish_{config,update_completions}: extract function for standalone builds

This commit is contained in:
Johannes Altmanninger
2025-10-13 18:20:08 +02:00
parent fad0e39cfa
commit a216cfdd2f
4 changed files with 62 additions and 53 deletions

View File

@@ -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

View File

@@ -0,0 +1,7 @@
# localization: skip(private)
function __fish_with_status
set -l saved_status $status
$argv
or return
return $saved_status
end

View File

@@ -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

View File

@@ -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