Add __fish_anypython helper function

This just finds the first usable python and echos it, so it can then
be used.

We have a few places where we use it and I'm about to add some more.
This commit is contained in:
Fabian Homborg 2019-03-09 17:57:49 +01:00
parent 3ac1c29f79
commit 9b1fb6938e
3 changed files with 14 additions and 12 deletions

View file

@ -0,0 +1,10 @@
function __fish_anypython
# Try python3 first, because that's usually faster and generally nicer.
for py in python3 python2 python
command -sq $py
and echo $py
and return 0
end
# We have no python.
return 1
end

View file

@ -1,11 +1,7 @@
function fish_config --description "Launch fish's web based configuration"
set -lx __fish_bin_dir $__fish_bin_dir
if command -sq python3
python3 "$__fish_data_dir/tools/web_config/webconfig.py" $argv
else if command -sq python2
python2 "$__fish_data_dir/tools/web_config/webconfig.py" $argv
else if command -sq python
python "$__fish_data_dir/tools/web_config/webconfig.py" $argv
if set -l python (__fish_anypython)
$python "$__fish_data_dir/tools/web_config/webconfig.py" $argv
else
echo (set_color $fish_color_error)Cannot launch the web configuration tool:(set_color normal)
echo (set_color -o)fish_config(set_color normal) requires Python.

View file

@ -2,12 +2,8 @@ function fish_update_completions --description "Update man-page based completion
# Don't write .pyc files, use the manpath, clean up old completions
# display progress.
set -l update_args -B $__fish_data_dir/tools/create_manpage_completions.py --manpath --cleanup-in ~/.config/fish/generated_completions --progress $argv
if command -qs python3
python3 $update_args
else if command -qs python2
python2 $update_args
else if command -qs python
python $update_args
if set -l python (__fish_anypython)
$python $update_args
else
printf "%s\n" (_ "python executable not found")
return 1