From 9b1fb6938e0e82ffea181e844540d1a426d22217 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 9 Mar 2019 17:57:49 +0100 Subject: [PATCH] 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. --- share/functions/__fish_anypython.fish | 10 ++++++++++ share/functions/fish_config.fish | 8 ++------ share/functions/fish_update_completions.fish | 8 ++------ 3 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 share/functions/__fish_anypython.fish diff --git a/share/functions/__fish_anypython.fish b/share/functions/__fish_anypython.fish new file mode 100644 index 000000000..3a3819864 --- /dev/null +++ b/share/functions/__fish_anypython.fish @@ -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 diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish index d4ef02c9a..aa05fa0f0 100644 --- a/share/functions/fish_config.fish +++ b/share/functions/fish_config.fish @@ -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. diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish index 96b55c59d..cf0151669 100644 --- a/share/functions/fish_update_completions.fish +++ b/share/functions/fish_update_completions.fish @@ -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