From ba3f26ddd2cd2752f296adb625e7312eecf16b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 08:12:54 +0300 Subject: [PATCH 01/13] refactor(bts): generator naming, remove redundant COMPREPLY clearances --- completions/bts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/completions/bts b/completions/bts index 65e85045abe..bdf8df0d049 100644 --- a/completions/bts +++ b/completions/bts @@ -1,8 +1,7 @@ # bts completion -*- shell-script -*- # Generate bug numbers from bugs cache in ~/.devscripts_cache/bts -# TODO:API: generator -_comp_cmd_bts__cached_bugs() +_comp_cmd_bts__compgen_cached_bugs() { [[ -d $HOME/.devscripts_cache/bts ]] || return 1 local bugs=$( @@ -14,8 +13,7 @@ _comp_cmd_bts__cached_bugs() } # Generate APT source packages prefixed with "src:" -# TODO:API: generator -_comp_cmd_bts__src_packages_with_prefix() +_comp_cmd_bts__compgen_src_packages_with_prefix() { local ppn=${cur:4} # partial package name, after stripping "src:" _comp_compgen -ac "$ppn" split -P "src:" -- \ @@ -30,8 +28,8 @@ _comp_cmd_bts() case $prev in show | bugs) _comp_compgen -- -W 'release-critical RC from: tag: usertag:' - _comp_cmd_bts__cached_bugs - _comp_cmd_bts__src_packages_with_prefix + _comp_cmd_bts__compgen_cached_bugs + _comp_cmd_bts__compgen_src_packages_with_prefix return ;; select) @@ -42,7 +40,7 @@ _comp_cmd_bts() ;; status) _comp_compgen -- -W 'file: fields: verbose' - _comp_cmd_bts__cached_bugs + _comp_cmd_bts__compgen_cached_bugs return ;; block | unblock) @@ -60,8 +58,7 @@ _comp_cmd_bts() return ;; clone | "done" | reopen | archive | unarchive | retitle | summary | submitter | found | notfound | fixed | notfixed | merge | forcemerge | unmerge | claim | unclaim | forwarded | notforwarded | owner | noowner | subscribe | unsubscribe | reportspam | spamreport | affects | usertag | usertags | reassign | tag | tags) - COMPREPLY=() - _comp_cmd_bts__cached_bugs + _comp_cmd_bts__compgen_cached_bugs return ;; package) @@ -70,19 +67,18 @@ _comp_cmd_bts() ;; cache) COMPREPLY=($(_comp_xfunc apt-cache packages)) - _comp_cmd_bts__src_packages_with_prefix + _comp_cmd_bts__compgen_src_packages_with_prefix _comp_compgen -a -- -W 'from: release-critical RC' return ;; cleancache) COMPREPLY=($(_comp_xfunc apt-cache packages)) - _comp_cmd_bts__src_packages_with_prefix + _comp_cmd_bts__compgen_src_packages_with_prefix _comp_compgen -a -- -W 'from: tag: usertag: ALL' return ;; user) # non-predicible arguments - COMPREPLY=() return ;; :) From 0dea0e4b768c8570dd48139ca1f117e06f0eb815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:00:38 +0300 Subject: [PATCH 02/13] refactor(xrandr): internal helpers to generators Co-authored-by: Koichi Murase --- completions/xrandr | 93 ++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/completions/xrandr b/completions/xrandr index 871c49a074a..52d443c046a 100644 --- a/completions/xrandr +++ b/completions/xrandr @@ -1,44 +1,45 @@ # bash completion for xrandr -*- shell-script -*- -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_outputs() +_comp_cmd_xrandr__compgen_outputs() { - "$1" -q 2>/dev/null | awk '/connected/ {print $1}' + _comp_compgen_split -- "$("$1" -q 2>/dev/null | awk '/connected/ {print $1}')" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_monitors() +_comp_cmd_xrandr__compgen_monitors() { - "$1" --listmonitors 2>/dev/null | - command sed -ne 's/.* [0-9]*: [+\*]*\([^ ]*\).*/\1/p' + _comp_compgen_split -- "$( + "$1" --listmonitors 2>/dev/null | + command sed -ne 's/.* [0-9]*: [+\*]*\([^ ]*\).*/\1/p' + )" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_providers() +_comp_cmd_xrandr__compgen_providers() { - "$1" --listproviders 2>/dev/null | - command sed -ne "s/.*cap:.*$2.* name:\([^ ]*\).*/\1/p" + _comp_compgen_split -- "$("$1" --listproviders 2>/dev/null | + command sed -ne "s/.*cap:.*$2.* name:\([^ ]*\).*/\1/p")" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_modes() +_comp_cmd_xrandr__compgen_modes() { - "$1" -q 2>/dev/null | command sed \ - -e "1,/^$2 / d" \ - -e '/connected/,$ d' \ - -e '/^[[:space:]]*h: / d' \ - -e '/^[[:space:]]*v: / d' \ - -e 's/\([^[:space:]]\)[[:space:]].*/\1/' + _comp_compgen_split -- "$( + "$1" -q 2>/dev/null | command sed \ + -e "1,/^$2 / d" \ + -e '/connected/,$ d' \ + -e '/^[[:space:]]*h: / d' \ + -e '/^[[:space:]]*v: / d' \ + -e 's/\([^[:space:]]\)[[:space:]].*/\1/' + )" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_all_modes() +_comp_cmd_xrandr__compgen_all_modes() { - "$1" -q 2>/dev/null | command sed \ - -e '/^[^[:space:]].*/ d' \ - -e '/^[[:space:]]*h: / d' \ - -e '/^[[:space:]]*v: / d' \ - -e 's/[[:space:]]*\([^[:space:]]*\)[[:space:]].*/\1/' + _comp_compgen_split -- "$( + "$1" -q 2>/dev/null | command sed \ + -e '/^[^[:space:]].*/ d' \ + -e '/^[[:space:]]*h: / d' \ + -e '/^[[:space:]]*v: / d' \ + -e 's/[[:space:]]*\([^[:space:]]*\)[[:space:]].*/\1/' + )" } # TODO:API: rename per conventions, rework to use vars rather than outputting @@ -68,21 +69,18 @@ _comp_cmd_xrandr() return ;; --output | --addmode | --delmode | --dpi) - local outputs=$(_comp_cmd_xrandr_outputs "$1") - _comp_compgen -- -W "$outputs" + _comp_cmd_xrandr__compgen_outputs "$1" return ;; --left-of | --right-of | --above | --below | --same-as) if [[ $has_output ]]; then - local outputs=$(_comp_cmd_xrandr_outputs "$1") - _comp_compgen -- -W "$outputs" + _comp_cmd_xrandr__compgen_outputs "$1" fi return ;; --mode) if [[ $has_output ]]; then - local modes=$(_comp_cmd_xrandr_modes "$1" "$output") - _comp_compgen -- -W "$modes" + _comp_cmd_xrandr__compgen_modes "$1" "$output" fi return ;; @@ -109,18 +107,15 @@ _comp_cmd_xrandr() return ;; --setprovideroutputsource) - local providers=$(_comp_cmd_xrandr_providers "$1" "Sink Output") - _comp_compgen -- -W "$providers" + _comp_cmd_xrandr__compgen_providers "$1" "Sink Output" return ;; --setprovideroffloadsink) - local providers=$(_comp_cmd_xrandr_providers "$1" "Source Offload") - _comp_compgen -- -W "$providers" + _comp_cmd_xrandr__compgen_providers "$1" "Source Offload" return ;; --delmonitor) - local monitors=$(_comp_cmd_xrandr_monitors "$1") - _comp_compgen -- -W "$monitors" + _comp_cmd_xrandr__compgen_monitors "$1" return ;; esac @@ -132,13 +127,11 @@ _comp_cmd_xrandr() return ;; --addmode) - local modes=$(_comp_cmd_xrandr_all_modes "$1") - _comp_compgen -- -W "$modes" + _comp_cmd_xrandr__compgen_all_modes "$1" return ;; --delmode) - local modes=$(_comp_cmd_xrandr_modes "$1" "${words[cword - 1]}") - _comp_compgen -- -W "$modes" + _comp_cmd_xrandr__compgen_modes "$1" "${words[cword - 1]}" return ;; --setmonitor) @@ -146,17 +139,13 @@ _comp_cmd_xrandr() return ;; --setprovideroutputsource) - local providers=$( - _comp_cmd_xrandr_providers "$1" "Source Output" - ) - _comp_compgen -- -W "0x0 $providers" + _comp_cmd_xrandr__compgen_providers "$1" "Source Output" + _comp_compgen -a -- -W "0x0" return ;; --setprovideroffloadsink) - local providers=$( - _comp_cmd_xrandr_providers "$1" "Sink Offload" - ) - _comp_compgen -- -W "0x0 $providers" + _comp_cmd_xrandr__compgen_providers "$1" "Sink Offload" + _comp_compgen -a -- -W "0x0" return ;; esac @@ -166,8 +155,8 @@ _comp_cmd_xrandr() if ((cword >= 3)); then case "${words[cword - 3]}" in --setmonitor) - local outputs=$(_comp_cmd_xrandr_outputs "$1") - _comp_compgen -- -W "none $outputs" + _comp_cmd_xrandr__compgen_outputs "$1" + _comp_compgen -a -- -W "none" # TODO: the third argument is actually a comma-separated list return ;; From d44c288c592bf410b82f1f7007978fc6261b1e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:02:43 +0300 Subject: [PATCH 03/13] refactor(xrandr): inline `_comp_cmd_xrandr_help` Not complex enough to warrant a separate function, and usages are adjacent. --- completions/xrandr | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/completions/xrandr b/completions/xrandr index 52d443c046a..2b6da2ceb08 100644 --- a/completions/xrandr +++ b/completions/xrandr @@ -42,12 +42,6 @@ _comp_cmd_xrandr__compgen_all_modes() )" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_comp_cmd_xrandr_help() -{ - "$1" --help 2>/dev/null -} - _comp_cmd_xrandr() { local cur prev words cword comp_args @@ -166,13 +160,13 @@ _comp_cmd_xrandr() local options if [[ $has_output ]]; then _comp_compgen -v options help - <<<"$( - _comp_cmd_xrandr_help "$1" | + "$1" --help 2>/dev/null | command sed -e 's/ or /\n /g' -e 's/<[^>]*>]//g' )" else # if no output is specified, remove per-output options _comp_compgen -v options help - <<<"$( - _comp_cmd_xrandr_help "$1" | + "$1" --help 2>/dev/null | command sed -e '/^ -/!d' -e 's/ or /\n /g' -e 's/<[^>]*>]//g' )" fi From 2097aed01f5b924621ffe4cb74017c83850b190d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:13:54 +0300 Subject: [PATCH 04/13] refactor(openssl): internal helpers to generators --- completions/openssl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/completions/openssl b/completions/openssl index 0dc8aad8d8a..6bc5dc4db8e 100644 --- a/completions/openssl +++ b/completions/openssl @@ -1,6 +1,6 @@ # bash completion for openssl -*- shell-script -*- -_comp_cmd_openssl__sections() +_comp_cmd_openssl__compgen_sections() { local config f @@ -25,15 +25,16 @@ _comp_cmd_openssl__sections() _comp_compgen_split -- "$(awk '/\[.*\]/ {print $2}' "$config")" } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_openssl_digests() +_comp_cmd_openssl__compgen_digests() { - "$1" dgst -h 2>&1 | - awk '/^-.*[ \t]to use the .* message digest algorithm/ { print $1 }' - local -a digests=($("$1" help 2>&1 | - command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' | - command sed -e 1d)) - printf "%s\n" "${digests[@]/#/-}" + _comp_compgen_split -- "$( + "$1" dgst -h 2>&1 | + awk '/^-.*[ \t]to use the .* message digest algorithm/ { print $1 }' + local -a digests=($("$1" help 2>&1 | + command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' | + command sed -e 1d)) + printf "%s\n" "${digests[@]/#/-}" + )" } _comp_cmd_openssl() @@ -74,7 +75,7 @@ _comp_cmd_openssl() return ;; -name | -crlexts | -extensions) - _comp_cmd_openssl__sections + _comp_cmd_openssl__compgen_sections return ;; -inform | -outform | -keyform | -certform | -CAform | -CAkeyform | -dkeyform | \ @@ -118,8 +119,7 @@ _comp_cmd_openssl() _comp_compgen_help -- "$command" -help case $command in dgst | req | x509) - local options=$(_openssl_digests "$1") - _comp_compgen -a -- -W '$options' + _comp_compgen -a -i openssl digests "$1" ;; esac else From e32a58b3dcbd461284bcebdd7740e2cbf4c18e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:25:10 +0300 Subject: [PATCH 05/13] refactor(dict): internal helper to generator Co-authored-by: Koichi Murase --- completions/dict | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/completions/dict b/completions/dict index 73ebd4dcc2b..eefb80ed97e 100644 --- a/completions/dict +++ b/completions/dict @@ -1,10 +1,12 @@ # dict(1) completion -*- shell-script -*- -# TODO:API: rename per conventions, rework to use vars rather than outputting -_dictdata() +_comp_cmd_dict__compgen_dictdata() { - dict "$@" 2>/dev/null | command sed -ne \ - 's/^[[:blank:]]\{1,\}\([^[:blank:]]*\).*$/\1/p' + # shellcheck disable=SC2086 + _comp_compgen_split -- "$( + "$@" 2>/dev/null | command sed -ne \ + 's/^[[:blank:]]\{1,\}\([^[:blank:]]*\).*$/\1/p' + )" } _comp_cmd_dict() @@ -42,11 +44,11 @@ _comp_cmd_dict() # shellcheck disable=SC2254 case $prev in --database | -info | -${noargopts}[di]) - _comp_compgen_split -- "$(_dictdata ${dict_options[@]+"${dict_options[@]}"} -D)" + _comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -D return ;; --strategy | -${noargopts}s) - _comp_compgen_split -- "$(_dictdata ${dict_options[@]+"${dict_options[@]}"} -S)" + _comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -S return ;; esac From 3cbb8ef79add5a51d7dec5fa1a30c3ea23af851f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:26:23 +0300 Subject: [PATCH 06/13] chore(modules): remove stale TODOs --- completions/_modules | 4 ---- 1 file changed, 4 deletions(-) diff --git a/completions/_modules b/completions/_modules index f549cd19f88..f628f5a924a 100644 --- a/completions/_modules +++ b/completions/_modules @@ -61,22 +61,18 @@ _comp_cmd_module() elif ((cword == 2)); then case $prev in add | display | help | load | show | whatis) - # TODO:API: use generator call? _comp_cmd_module__compgen_avail ;; rm | switch | swap | unload | update) - # TODO:API: use generator call? _comp_cmd_module__compgen_list ;; unuse) - # TODO:API: use generator call? _comp_cmd_module__compgen_path ;; esac elif ((cword == 3)); then case ${words[1]} in swap | switch) - # TODO:API: use generator call? _comp_cmd_module__compgen_avail ;; esac From b9a2763269a68f881371a0c392f55318d0a766e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 09:37:45 +0300 Subject: [PATCH 07/13] refactor(cvs): some internal helpers to generators --- completions/cvs | 58 ++++++++++++++++++++++++----------------------- completions/cvsps | 4 ++-- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/completions/cvs b/completions/cvs index aeda845bfcf..8a8692da1f7 100644 --- a/completions/cvs +++ b/completions/cvs @@ -20,24 +20,25 @@ _comp_cmd_cvs__modules() fi } -# TODO:API: rename per conventions, rework to use vars rather than outputting -_cvs_commands() +_comp_cmd_cvs__compgen_commands() { - cvs --help-commands 2>&1 | awk '/^( *|\t)/ { print $1 }' + _comp_compgen_split -- "$( + "$1" --help-commands 2>&1 | awk '/^( *|\t)/ { print $1 }' + )" } -_comp_cmd_cvs__command_options() +_comp_cmd_cvs__compgen_command_options() { _comp_compgen_help -- --help "$2" } -_comp_cmd_cvs__kflags() +_comp_cmd_cvs__compgen_kflags() { _comp_compgen -- -W 'kv kvl k o b v' } # @since 2.12 -_comp_xfunc_cvs_roots() +_comp_xfunc_cvs_compgen_roots() { local -a cvsroots=() [[ -v CVSROOT ]] && cvsroots=("$CVSROOT") @@ -48,7 +49,7 @@ _comp_xfunc_cvs_roots() _comp_ltrim_colon_completions "$cur" } -_comp_deprecate_func 2.12 _cvs_roots _comp_xfunc_cvs_roots +_comp_deprecate_func 2.12 _cvs_roots _comp_xfunc_cvs_compgen_roots _comp_cmd_cvs() { @@ -70,7 +71,7 @@ _comp_cmd_cvs() # shellcheck disable=SC2254 case $i in --help | -${noargopts}H) - _comp_compgen_split -- "$(_cvs_commands)" + _comp_cmd_cvs__compgen_commands "$1" return ;; -${noargopts}d) @@ -153,7 +154,7 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac @@ -179,7 +180,7 @@ _comp_cmd_cvs() ((${#files[@]})) && _comp_compgen -- -X "$_comp_backup_glob" -W '"${files[@]}"' else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; admin) @@ -193,13 +194,13 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac if [[ $cur == -* ]]; then - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" else _comp_cmd_cvs__entries ((${#entries[@]})) && @@ -210,7 +211,7 @@ _comp_cmd_cvs() [[ $prev == -[rD] ]] && return if [[ $cur == -* ]]; then - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" else _comp_cmd_cvs__entries ((${#entries[@]})) && @@ -228,7 +229,7 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac @@ -240,7 +241,7 @@ _comp_cmd_cvs() ((${#COMPREPLY[@]})) && _comp_compgen -- -W '"${COMPREPLY[@]}"' else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; commit) @@ -277,15 +278,15 @@ _comp_cmd_cvs() _comp_compgen -- -W '"${entries[@]}"' fi else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; cvsroot) - _comp_xfunc_cvs_roots + _comp_xfunc_cvs_compgen_roots ;; diff | log | status) if [[ $cur == -* ]]; then - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" [[ ${COMPREPLY-} == *= ]] && compopt -o nospace else _comp_cmd_cvs__entries @@ -295,7 +296,7 @@ _comp_cmd_cvs() ;; editors | watchers) if [[ $cur == -* ]]; then - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" else _comp_cmd_cvs__entries ((${#entries[@]})) && @@ -313,7 +314,7 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac @@ -324,7 +325,7 @@ _comp_cmd_cvs() ((${#COMPREPLY[@]})) && _comp_compgen -- -W '"${COMPREPLY[@]}"' else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; import) @@ -334,7 +335,7 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac @@ -354,7 +355,7 @@ _comp_cmd_cvs() ((${#COMPREPLY[@]})) && _comp_compgen -- -W '"${COMPREPLY[@]}"' else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; remove) @@ -369,7 +370,7 @@ _comp_cmd_cvs() ((${#entries[@]})) && _comp_compgen -- -W '"${entries[@]}"' else - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" fi ;; update) @@ -379,13 +380,13 @@ _comp_cmd_cvs() return ;; -*k) - _comp_cmd_cvs__kflags + _comp_cmd_cvs__compgen_kflags return ;; esac if [[ $cur == -* ]]; then - _comp_cmd_cvs__command_options "$1" "$mode" + _comp_cmd_cvs__compgen_command_options "$1" "$mode" else _comp_cmd_cvs__entries ((${#entries[@]})) && @@ -409,8 +410,9 @@ _comp_cmd_cvs() esac _comp_compgen_help -- --help-options - _comp_compgen -a split -- "$(_cvs_commands) --help - --help-commands --help-options --version" + _comp_compgen -a -i cvs commands "$1" + _comp_compgen -a -- -W \ + "--help --help-commands --help-options --version" ;; esac diff --git a/completions/cvsps b/completions/cvsps index b445e5c8d5e..3de853db8f6 100644 --- a/completions/cvsps +++ b/completions/cvsps @@ -42,7 +42,7 @@ _comp_cmd_cvsps() return ;; --root) - _comp_xfunc cvs roots + _comp_compgen -x cvs roots return ;; esac @@ -50,7 +50,7 @@ _comp_cmd_cvsps() if [[ $cur == -* ]]; then _comp_compgen_help -- -h else - _comp_xfunc cvs roots + _comp_compgen -x cvs roots fi } && complete -F _comp_cmd_cvsps cvsps From f92ef41590678d911378cdd64814ffcc86131bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 10:27:45 +0300 Subject: [PATCH 08/13] refactor(ssh): more helpers to generators, replace by default --- completions/curl | 2 +- completions/rsync | 2 +- completions/ssh | 112 ++++++++++++++++++++++------------------ completions/ssh-copy-id | 2 +- completions/ssh-keygen | 6 +-- completions/sshfs | 2 +- 6 files changed, 69 insertions(+), 57 deletions(-) diff --git a/completions/curl b/completions/curl index 1e2760f969b..7b9124f896c 100644 --- a/completions/curl +++ b/completions/curl @@ -130,7 +130,7 @@ _comp_cmd_curl() return ;; --pubkey) - _comp_xfunc ssh identityfile pub + _comp_compgen -x ssh identityfile pub return ;; --request | -${noargopts}X) diff --git a/completions/rsync b/completions/rsync index e9dba692683..2fa2dcc1bac 100644 --- a/completions/rsync +++ b/completions/rsync @@ -81,7 +81,7 @@ _comp_cmd_rsync() break fi done - [[ $shell == ssh ]] && _comp_xfunc scp remote_files + [[ $shell == ssh ]] && _comp_compgen -x scp remote_files ;; *) _known_hosts_real -c -a -- "$cur" diff --git a/completions/ssh b/completions/ssh index 705343ae71f..4cd28d324ef 100644 --- a/completions/ssh +++ b/completions/ssh @@ -1,52 +1,56 @@ # ssh(1) completion -*- shell-script -*- -_comp_cmd_ssh__queries() +_comp_cmd_ssh__compgen_queries() { - local queries=$(_comp_cmd_ssh__query "$1" help) - [[ $queries ]] || queries="cipher cipher-auth mac kex key key-cert - key-plain key-sig protocol-version compression sig ciphers macs - kexalgorithms pubkeyacceptedkeytypes hostkeyalgorithms - hostbasedkeytypes hostbasedacceptedkeytypes" - _comp_compgen -ac "${cur,,}" -- -W "$queries help" + local -a ret + _comp_compgen -v ret -i ssh query "$1" help + [[ ${ret-} ]] || ret=(cipher cipher-auth mac kex key key-cert + key-plain key-sig protocol-version compression sig ciphers macs + kexalgorithms pubkeyacceptedkeytypes hostkeyalgorithms + hostbasedkeytypes hostbasedacceptedkeytypes) + _comp_compgen -ac "${cur,,}" -- -W '"${ret[@]}" help"' } # @since 2.12 -# TODO:API:rework to use vars rather than outputting -_comp_xfunc_ssh_query() +_comp_xfunc_ssh_compgen_query() { - _comp_cmd_ssh__query ssh "$1" + _comp_cmd_ssh__compgen_query ssh "$1" } -# @deprecated 2.12 use _comp_xfunc_ssh_query +# @deprecated 2.12 use _comp_xfunc_ssh_compgen_query _ssh_query() { - _comp_cmd_ssh__query "${1:-ssh}" "$2" + local -a ret=() + _comp_compgen -v ret -i ssh query "${1:-ssh}" "$2" + printf "%s\n" "${ret[@]}" } -# TODO:API:rework to use vars rather than outputting -_comp_cmd_ssh__query() +_comp_cmd_ssh__compgen_query() { - "$1" -Q "$2" 2>/dev/null + _comp_compgen_split -- "$("$1" -Q "$2" 2>/dev/null)" } -_comp_cmd_ssh__ciphers() +_comp_cmd_ssh__compgen_ciphers() { - local ciphers=$(_comp_cmd_ssh__query "$1" cipher) - [[ $ciphers ]] || ciphers="3des-cbc aes128-cbc aes192-cbc aes256-cbc + local -a ret + _comp_compgen -v ret -i ssh query "$1" cipher + [[ ${ret-} ]] || ret=(3des-cbc aes128-cbc aes192-cbc aes256-cbc aes128-ctr aes192-ctr aes256-ctr arcfour128 arcfour256 arcfour - blowfish-cbc cast128-cbc" - _comp_compgen -a -- -W "$ciphers" + blowfish-cbc cast128-cbc) + _comp_compgen -a -- -W '"${ret[@]}"' } -_comp_cmd_ssh__macs() +_comp_cmd_ssh__compgen_macs() { - local macs=$(_comp_cmd_ssh__query "$1" mac) - [[ $macs ]] || macs="hmac-md5 hmac-sha1 umac-64@openssh.com hmac-ripemd160 - hmac-sha1-96 hmac-md5-96" - _comp_compgen -a -- -W "$macs" + local -a ret + _comp_compgen -v ret -i ssh query "$1" mac + [[ ${ret-} ]] || ret=(hmac-md5 hmac-sha1 umac-64@openssh.com + hmac-ripemd160 hmac-sha1-96 hmac-md5-96) + _comp_compgen -a -- -W '"${ret[@]}"' } # @since 2.12 +# TODO:API: make it a generator _comp_xfunc_ssh_options() { # curl --silent https://raw.githubusercontent.com/openssh/openssh-portable/master/ssh_config.5 | awk '$1==".It" && $2=="Cm" && $3!="Host" && $3!="Match" {print " "$3}' | sort @@ -80,8 +84,9 @@ _comp_xfunc_ssh_options() GSSAPIKeyExchange GSSAPIRenewalForcesRekey GSSAPIServerIdentity GSSAPITrustDns PubkeyAcceptedKeyTypes SmartcardDevice UsePrivilegedPort ) - local protocols=$(_comp_cmd_ssh__query ssh protocol-version) - if [[ ! $protocols || $protocols == *1* ]]; then + local -a protocols + _comp_compgen -v protocols -i ssh query ssh protocol-version + if [[ ${protocols[*]} == *1* ]]; then opts+=(Cipher CompressionLevel Protocol RhostsRSAAuthentication RSAAuthentication) fi @@ -138,20 +143,20 @@ _comp_cmd_ssh__suboption() _comp_compgen -- -W 'yes no always' ;; identityfile) - _comp_xfunc_ssh_identityfile + _comp_xfunc_ssh_compgen_identityfile ;; *file | identityagent | include | controlpath | revokedhostkeys | \ xauthlocation) _comp_compgen_filedir ;; casignaturealgorithms) - _comp_compgen_split -- "$(_comp_cmd_ssh__query "$1" sig)" + _comp_cmd_ssh__compgen_query "$1" sig ;; cipher) _comp_compgen -- -W 'blowfish des 3des' ;; ciphers) - _comp_cmd_ssh__ciphers "$1" + _comp_cmd_ssh__compgen_ciphers "$1" ;; controlmaster) _comp_compgen -- -W 'yes ask auto autoask no' @@ -167,16 +172,16 @@ _comp_cmd_ssh__suboption() cs{0..7} ef lowdelay throughput reliability' ;; hostbasedkeytypes | hostkeyalgorithms) - _comp_compgen_split -- "$(_comp_cmd_ssh__query "$1" key)" + _comp_cmd_ssh__compgen_query "$1" key ;; kexalgorithms) - _comp_compgen_split -- "$(_comp_cmd_ssh__query "$1" kex)" + _comp_cmd_ssh__compgen_query "$1" kex ;; loglevel) _comp_compgen -- -W 'QUIET FATAL ERROR INFO VERBOSE DEBUG{,1,2,3}' ;; macs) - _comp_cmd_ssh__macs "$1" + _comp_cmd_ssh__compgen_macs "$1" ;; pkcs11provider) _comp_compgen_filedir so @@ -186,8 +191,9 @@ _comp_cmd_ssh__suboption() keyboard-interactive password' ;; protocol) - local protocols=($(_comp_cmd_ssh__query "$1" protocol-version)) - [[ $protocols ]] || protocols=(1 2) + local -a protocols + _comp_compgen -v protocols -i ssh query "$1" protocol-version + [[ ${protocols-} ]] || protocols=(1 2) if ((${#protocols[@]} > 1)); then _comp_compgen -- -W '"${protocols[@]}"' fi @@ -199,7 +205,7 @@ _comp_cmd_ssh__suboption() _comp_compgen_commands ;; pubkeyacceptedalgorithms | pubkeyacceptedkeytypes) - _comp_compgen_split -- "$(_comp_cmd_ssh__query "$1" key)" + _comp_cmd_ssh__compgen_query "$1" key ;; requesttty) _comp_compgen -- -W 'no yes force auto' @@ -224,6 +230,7 @@ _comp_cmd_ssh__suboption() # # Returns 0 if the completion was handled or non-zero otherwise. # @since 2.12 +# # TODO:API: make it a generator _comp_xfunc_ssh_suboption_check() { _comp_cmd_ssh__suboption_check ssh @@ -271,7 +278,7 @@ _comp_cmd_ssh__configfile() # With $1 set, look for public key files, else private # @since 2.12 # shellcheck disable=SC2120 -_comp_xfunc_ssh_identityfile() +_comp_xfunc_ssh_compgen_identityfile() { local cur=$cur tmp [[ ! $cur && -d ~/.ssh ]] && cur=~/.ssh/id @@ -279,7 +286,7 @@ _comp_xfunc_ssh_identityfile() _comp_compgen -- -W '"${tmp[@]}"' -X "${1:+!}*.pub" } -_comp_deprecate_func 2.12 _ssh_identityfile _comp_xfunc_ssh_identityfile +_comp_deprecate_func 2.12 _ssh_identityfile _comp_xfunc_ssh_compgen_identityfile _comp_cmd_ssh() { @@ -305,7 +312,7 @@ _comp_cmd_ssh() return ;; -*c) - _comp_cmd_ssh__ciphers "$1" + _comp_cmd_ssh__compgen_ciphers "$1" return ;; -*[DeLpRW]) @@ -320,7 +327,7 @@ _comp_cmd_ssh() return ;; -*i) - _comp_xfunc_ssh_identityfile + _comp_xfunc_ssh_compgen_identityfile return ;; -*J) @@ -332,7 +339,7 @@ _comp_cmd_ssh() return ;; -*m) - _comp_cmd_ssh__macs "$1" + _comp_cmd_ssh__compgen_macs "$1" return ;; -*O) @@ -344,7 +351,7 @@ _comp_cmd_ssh() return ;; -*Q) - _comp_cmd_ssh__queries "$1" + _comp_cmd_ssh__compgen_queries "$1" return ;; -*w) @@ -408,11 +415,11 @@ _comp_cmd_sftp() return ;; -*i) - _comp_xfunc_ssh_identityfile + _comp_xfunc_ssh_compgen_identityfile return ;; -*c) - _comp_cmd_ssh__ciphers + _comp_cmd_ssh__compgen_ciphers return ;; -*J) @@ -455,7 +462,7 @@ _comp_cmd_scp__path_esc='[][(){}<>"'"'"',:;^&!$=?`\\|[:space:]]' # only. Returns paths escaped with three backslashes. # @since 2.12 # shellcheck disable=SC2120 -_comp_xfunc_scp_remote_files() +_comp_xfunc_scp_compgen_remote_files() { # remove backslash escape from the first colon cur=${cur/\\:/:} @@ -488,16 +495,21 @@ _comp_xfunc_scp_remote_files() command sed -e 's/'"$_comp_cmd_scp__path_esc"'/\\\\\\&/g' -e 's/[*@|=]$//g' \ -e 's/[^\/]$/& /g') fi - _comp_split -la COMPREPLY "$files" + _comp_split -l COMPREPLY "$files" } -_comp_deprecate_func 2.12 _scp_remote_files _comp_xfunc_scp_remote_files +# @deprecated 2.12 use `_comp_compgen -ax ssh remote_files` instead +_scp_remote_files() +{ + _comp_compgen -ax scp remote_files +} # This approach is used instead of _comp_compgen_filedir to get a space # appended after local file/dir completions, and -o nospace retained for # others. If first arg is -d, complete on directory names only. The next arg # is an optional prefix to add to returned completions. # @since 2.12 +# TODO:API: make it a generator, don't append by default _comp_xfunc_scp_local_files() { local IFS=$'\n' @@ -547,7 +559,7 @@ _comp_cmd_scp() case $prev in -*c) - _comp_cmd_ssh__ciphers + _comp_cmd_ssh__compgen_ciphers COMPREPLY=("${COMPREPLY[@]/%/ }") return ;; @@ -557,7 +569,7 @@ _comp_cmd_scp() return ;; -*i) - _comp_xfunc_ssh_identityfile + _comp_xfunc_ssh_compgen_identityfile compopt +o nospace return ;; @@ -590,7 +602,7 @@ _comp_cmd_scp() case $cur in !(*:*)/* | [.~]*) ;; # looks like a path *:*) - _comp_xfunc_scp_remote_files + _comp_xfunc_scp_compgen_remote_files return ;; esac diff --git a/completions/ssh-copy-id b/completions/ssh-copy-id index 93da9ceeae5..ff13012c696 100644 --- a/completions/ssh-copy-id +++ b/completions/ssh-copy-id @@ -13,7 +13,7 @@ _comp_cmd_ssh_copy_id() case $prev in -i) - _comp_xfunc ssh identityfile pub + _comp_compgen -x ssh identityfile pub return ;; -p) diff --git a/completions/ssh-keygen b/completions/ssh-keygen index ccdc54efdc2..bd13b55692f 100644 --- a/completions/ssh-keygen +++ b/completions/ssh-keygen @@ -100,11 +100,11 @@ _comp_cmd_ssh_keygen() ;; -*t) # Prefer `ssh` from same dir for resolving options, etc - local pathcmd + local pathcmd protocols pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - local protocols=$(_comp_xfunc ssh query protocol-version) + _comp_compgen -v protocols -x ssh query protocol-version local types='dsa ecdsa ecdsa-sk ed25519 ed25519-sk rsa' - if [[ $protocols == *1* ]]; then + if [[ ${protocols[*]} == *1* ]]; then types+=' rsa1' fi _comp_compgen -- -W "$types" diff --git a/completions/sshfs b/completions/sshfs index d176cea9b49..34d25e773d9 100644 --- a/completions/sshfs +++ b/completions/sshfs @@ -8,7 +8,7 @@ _comp_cmd_sshfs() _expand || return if [[ $cur == *:* ]]; then - _comp_xfunc scp remote_files -d + _comp_compgen -x scp remote_files -d # unlike scp and rsync, sshfs works with 1 backslash instead of 3 COMPREPLY=("${COMPREPLY[@]//\\\\\\/\\}") return From dcf142a00178b56fedadcc5a152208fec2c9706b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 11:16:58 +0300 Subject: [PATCH 09/13] refactor(python): xfuncs to generators, replace by default Co-authored-by: Koichi Murase --- completions/mypy | 2 +- completions/pydoc | 2 +- completions/pylint | 4 ++-- completions/pytest | 2 +- completions/python | 27 +++++++++++++++------------ 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/completions/mypy b/completions/mypy index 9defe32a624..1c01ad4dcfb 100644 --- a/completions/mypy +++ b/completions/mypy @@ -33,7 +33,7 @@ _comp_cmd_mypy() return ;; --custom-typing-module | --module | -${noargopts}m) - _comp_xfunc python modules + _comp_compgen -x python modules return ;; --shadow-file) diff --git a/completions/pydoc b/completions/pydoc index ce0fc60360e..2cf29876904 100644 --- a/completions/pydoc +++ b/completions/pydoc @@ -26,7 +26,7 @@ _comp_cmd_pydoc() # Prefer python in the same dir for resolving modules local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc python modules + _comp_compgen -ax python modules fi # Note that we don't do "pydoc modules" as it is known to hang on diff --git a/completions/pylint b/completions/pylint index 5c0334b9917..266dcfafb55 100644 --- a/completions/pylint +++ b/completions/pylint @@ -72,7 +72,7 @@ _comp_cmd_pylint() return ;; --load-plugins | --deprecated-modules) - cur="${cur##*,}" _comp_xfunc python modules $python + _comp_compgen -c "${cur##*,}" -x python modules $python ((${#COMPREPLY[@]})) && _comp_delimited , -W '"${COMPREPLY[@]}"' return @@ -110,7 +110,7 @@ _comp_cmd_pylint() fi _comp_compgen_set - _comp_looks_like_path "$cur" || _comp_xfunc python modules $python + _comp_looks_like_path "$cur" || _comp_compgen -x python modules $python _comp_compgen -a filedir py } && complete -F _comp_cmd_pylint pylint pylint-2 pylint-3 diff --git a/completions/pytest b/completions/pytest index 25eb097d51e..d7516b3bc52 100644 --- a/completions/pytest +++ b/completions/pytest @@ -77,7 +77,7 @@ _comp_cmd_pytest() return ;; --pythonwarnings | -${noargopts}W) - _comp_xfunc python warning_actions + _comp_compgen -x python warning_actions return ;; --numprocesses | -${noargopts}n) diff --git a/completions/python b/completions/python index 8bec5b875c5..920d9266ff6 100644 --- a/completions/python +++ b/completions/python @@ -1,34 +1,37 @@ # bash completion for python -*- shell-script -*- # @since 2.12 -_comp_xfunc_python_modules() +_comp_xfunc_python_compgen_modules() { local python=python [[ ${comp_args[0]##*/} == *3* ]] && python=python3 - _comp_cmd_python__modules "$python" + _comp_cmd_python__compgen_modules "$python" } -# @deprecated 2.12 use `_comp_xfunc_python_modules` instead +# @deprecated 2.12 use `_comp_xfunc_python_compgen_modules` instead _python_modules() { - _comp_cmd_python__modules "${1:-python}" + _comp_compgen -a -i python modules "${1:-python}" } -_comp_cmd_python__modules() +_comp_cmd_python__compgen_modules() { - _comp_compgen -a split -- "$("$1" \ + _comp_compgen_split -- "$("$1" \ "${BASH_SOURCE[0]%/*}/../helpers/python" "$cur" 2>/dev/null)" } # @since 2.12 -_comp_xfunc_python_warning_actions() +_comp_xfunc_python_compgen_warning_actions() { - _comp_compgen -a -- -W "ignore default all module once error" \ + _comp_compgen -- -W "ignore default all module once error" \ ${prefix:+-P "$prefix"} } -_comp_deprecate_func 2.12 _python_warning_actions \ - _comp_xfunc_python_warning_actions +# @deprecated 2.12 use `_comp_xfunc_python_compgen_warning_actions` instead +_python_warning_actions() +{ + _comp_compgen -a -i python warning_actions "${1:-python}" +} _comp_cmd_python() { @@ -82,7 +85,7 @@ _comp_cmd_python() return ;; -${noargopts}m) - _comp_cmd_python__modules "$1" + _comp_cmd_python__compgen_modules "$1" return ;; -${noargopts}Q) @@ -90,7 +93,7 @@ _comp_cmd_python() return ;; -${noargopts}W) - _comp_xfunc_python_warning_actions + _comp_xfunc_python_compgen_warning_actions return ;; -${noargopts}X) From ee0a81343213c455d7b989230cf356d09159a145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 11:23:15 +0300 Subject: [PATCH 10/13] refactor(list_lists): xfunc to generator --- completions/arch | 2 +- completions/change_pw | 2 +- completions/check_db | 2 +- completions/clone_member | 2 +- completions/find_member | 2 +- completions/inject | 2 +- completions/list_admins | 2 +- completions/list_lists | 5 +++-- completions/list_members | 2 +- completions/list_owners | 2 +- completions/newlist | 2 +- completions/remove_members | 2 +- completions/rmlist | 2 +- completions/sync_members | 2 +- completions/withlist | 2 +- 15 files changed, 17 insertions(+), 16 deletions(-) diff --git a/completions/arch b/completions/arch index fed1882acb3..7ca973880a5 100644 --- a/completions/arch +++ b/completions/arch @@ -35,7 +35,7 @@ _comp_have_command mailmanctl && # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists ;; 2) _comp_compgen_filedir diff --git a/completions/change_pw b/completions/change_pw index 8ce28c25ba6..819c082452b 100644 --- a/completions/change_pw +++ b/completions/change_pw @@ -10,7 +10,7 @@ _comp_cmd_change_pw() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists return ;; esac diff --git a/completions/check_db b/completions/check_db index 2beb14538c1..6480a11a1b3 100644 --- a/completions/check_db +++ b/completions/check_db @@ -11,7 +11,7 @@ _comp_cmd_check_db() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/clone_member b/completions/clone_member index 63df3705de4..01f87e6e314 100644 --- a/completions/clone_member +++ b/completions/clone_member @@ -10,7 +10,7 @@ _comp_cmd_clone_member() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists return ;; esac diff --git a/completions/find_member b/completions/find_member index 97cde25509e..d2620e898ee 100644 --- a/completions/find_member +++ b/completions/find_member @@ -10,7 +10,7 @@ _comp_cmd_find_member() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists return ;; esac diff --git a/completions/inject b/completions/inject index b3aac773669..4b46921b0a8 100644 --- a/completions/inject +++ b/completions/inject @@ -10,7 +10,7 @@ _comp_cmd_inject() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists return ;; esac diff --git a/completions/list_admins b/completions/list_admins index 1ae38a3cbf0..98452eb2828 100644 --- a/completions/list_admins +++ b/completions/list_admins @@ -11,7 +11,7 @@ _comp_cmd_list_admins() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/list_lists b/completions/list_lists index 4062c6267f2..0ae00af9552 100644 --- a/completions/list_lists +++ b/completions/list_lists @@ -1,12 +1,13 @@ # mailman list_lists completion -*- shell-script -*- # @since 2.12 -_comp_xfunc_list_lists_mailman_lists() +_comp_xfunc_list_lists_compgen_mailman_lists() { _comp_compgen_split -- "$(list_lists -b 2>/dev/null)" } -_comp_deprecate_func 2.12 _mailman_lists _comp_xfunc_list_lists_mailman_lists +_comp_deprecate_func 2.12 _mailman_lists \ + _comp_xfunc_list_lists_compgen_mailman_lists _comp_cmd_list_lists() { diff --git a/completions/list_members b/completions/list_members index 4c557a7b755..a15a2cca46d 100644 --- a/completions/list_members +++ b/completions/list_members @@ -29,7 +29,7 @@ _comp_cmd_list_members() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/list_owners b/completions/list_owners index fe942a2dad6..61791764111 100644 --- a/completions/list_owners +++ b/completions/list_owners @@ -11,7 +11,7 @@ _comp_cmd_list_owners() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/newlist b/completions/newlist index 9ab45dc92c3..b4e6060cf14 100644 --- a/completions/newlist +++ b/completions/newlist @@ -20,7 +20,7 @@ _comp_cmd_newlist() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && complete -F _comp_cmd_newlist newlist diff --git a/completions/remove_members b/completions/remove_members index 57dbf43d4e0..4689b03e9eb 100644 --- a/completions/remove_members +++ b/completions/remove_members @@ -21,7 +21,7 @@ _comp_cmd_remove_members() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/rmlist b/completions/rmlist index a661e7fc269..f3aca067910 100644 --- a/completions/rmlist +++ b/completions/rmlist @@ -11,7 +11,7 @@ _comp_cmd_rmlist() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/sync_members b/completions/sync_members index ccfd2303bfa..e8c07a7bc63 100644 --- a/completions/sync_members +++ b/completions/sync_members @@ -25,7 +25,7 @@ _comp_cmd_sync_members() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && diff --git a/completions/withlist b/completions/withlist index 1447db8eeb9..f6875111e70 100644 --- a/completions/withlist +++ b/completions/withlist @@ -11,7 +11,7 @@ _comp_cmd_withlist() # Prefer `list_lists` in the same dir as command local pathcmd pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH - _comp_xfunc list_lists mailman_lists + _comp_compgen -x list_lists mailman_lists fi } && From 0b85db3c246faf34de5fca1e98ccbbb2e242d88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 6 Aug 2023 11:31:02 +0300 Subject: [PATCH 11/13] chore: mark xfuncs in need of generator conversion as TODO --- completions/apt-cache | 10 +++++----- completions/apt-get | 1 + completions/asciidoc | 1 + completions/dpkg | 3 +++ completions/iconv | 2 ++ completions/mysql | 1 + completions/rpm | 2 ++ 7 files changed, 15 insertions(+), 5 deletions(-) diff --git a/completions/apt-cache b/completions/apt-cache index b83443b885b..44451984dff 100644 --- a/completions/apt-cache +++ b/completions/apt-cache @@ -1,28 +1,28 @@ # Debian apt-cache(8) completion -*- shell-script -*- # List APT binary packages -# TODO:API: rework to use vars rather than outputting +# TODO:API: make it a generator # @since 2.12 _comp_xfunc_apt_cache_packages() { _comp_cmd_apt_cache__packages apt-cache } -# TODO:API: rework to use vars rather than outputting +# TODO:API: make it a generator _comp_cmd_apt_cache__packages() { "$1" --no-generate pkgnames "$cur" 2>/dev/null || : } # List APT source packages -# TODO:API: rework to use vars rather than outputting +# TODO:API: make it a generator # @since 2.12 _comp_xfunc_apt_cache_sources() { _comp_cmd_apt_cache__sources apt-cache "$1" } -# TODO:API: rework to use vars rather than outputting +# TODO:API: make it a generator _comp_cmd_apt_cache__sources() { local ret @@ -32,7 +32,7 @@ _comp_cmd_apt_cache__sources() } # List APT source packages -# TODO:API: rework to use vars rather than outputting +# TODO:API: make it a generator # @since 2.12 _comp_xfunc_apt_cache_src_packages() { diff --git a/completions/apt-get b/completions/apt-get index 86ae7e76562..165ac546082 100644 --- a/completions/apt-get +++ b/completions/apt-get @@ -1,6 +1,7 @@ # Debian apt-get(8) completion -*- shell-script -*- # @since 2.12 +# TODO:API: make it a generator _comp_xfunc_apt_get_installed_packages() { if [[ -f /etc/debian_version ]]; then diff --git a/completions/asciidoc b/completions/asciidoc index 43626e4f3f8..1393bb2020e 100644 --- a/completions/asciidoc +++ b/completions/asciidoc @@ -1,6 +1,7 @@ # asciidoc(1) completion -*- shell-script -*- # @since 2.12 +# TODO:API: make it a default, replace by default _comp_xfunc_asciidoc_doctype() { _comp_compgen -a -- -W 'article book manpage' diff --git a/completions/dpkg b/completions/dpkg index ec310aae0cb..63b23bc6bd7 100644 --- a/completions/dpkg +++ b/completions/dpkg @@ -1,6 +1,7 @@ # dpkg(1) and related commands completion -*- shell-script -*- # @since 2.12 +# TODO:API: make it a generator, replace by default _comp_xfunc_dpkg_installed_packages() { local pkgs @@ -18,6 +19,7 @@ _comp_xfunc_dpkg_installed_packages() } # @since 2.12 +# TODO:API: make it a generator, replace by default _comp_xfunc_dpkg_purgeable_packages() { local pkgs @@ -35,6 +37,7 @@ _comp_xfunc_dpkg_purgeable_packages() } # @since 2.12 +# TODO:API: make it a generator, replace by default _comp_xfunc_dpkg_held_packages() { local pkgs=$(dpkg --get-selections ${cur:+"$cur}"} | diff --git a/completions/iconv b/completions/iconv index 9cfab2d5208..1f4b8ab2b8a 100644 --- a/completions/iconv +++ b/completions/iconv @@ -1,6 +1,7 @@ # iconv(1) completion -*- shell-script -*- # @since 2.12 +# TODO:API: make it a generator, replace by default _comp_xfunc_iconv_charsets() { _comp_cmd_iconv__charsets iconv @@ -12,6 +13,7 @@ _iconv_charsets() _comp_cmd_iconv__charsets "${1:-iconv}" } +# TODO:API: make it a generator, replace by default _comp_cmd_iconv__charsets() { _comp_compgen -a split -X ... -- "$("$1" -l | diff --git a/completions/mysql b/completions/mysql index 1a4aa992518..bb0d95d7115 100644 --- a/completions/mysql +++ b/completions/mysql @@ -1,6 +1,7 @@ # mysql(1) completion -*- shell-script -*- # @since 2.12 +# TODO:API: make it a generator, replace by default _comp_xfunc_mysql_character_sets() { local -a charsets diff --git a/completions/rpm b/completions/rpm index 32b50212167..10633892f3f 100644 --- a/completions/rpm +++ b/completions/rpm @@ -3,11 +3,13 @@ # helper functions # @since 2.12 +# TODO:API: make it a generator _comp_xfunc_rpm_installed_packages() { _comp_cmd_rpm__installed_packages rpm } +# TODO:API: make it a generator _comp_cmd_rpm__installed_packages() { if [[ -r /var/log/rpmpkgs && From d0695d0bc9d44d851d41b5c7e123ab6b95f29e81 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 12 Aug 2023 11:27:21 +0900 Subject: [PATCH 12/13] fix(ssh): work around bash-4.2 nounset --- completions/ssh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/ssh b/completions/ssh index 4cd28d324ef..9f6e024206a 100644 --- a/completions/ssh +++ b/completions/ssh @@ -86,7 +86,7 @@ _comp_xfunc_ssh_options() ) local -a protocols _comp_compgen -v protocols -i ssh query ssh protocol-version - if [[ ${protocols[*]} == *1* ]]; then + if [[ ${protocols[*]-} == *1* ]]; then opts+=(Cipher CompressionLevel Protocol RhostsRSAAuthentication RSAAuthentication) fi From cc212983a2b2523e5b62e9735c6dff5f011bb80a Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sat, 12 Aug 2023 11:42:43 +0900 Subject: [PATCH 13/13] fix(dict): work around bash-4.3 ${v+"$@"} with custom IFS Bash < 4.4 has a bug that all the elements are connected with `${v+"$@"}` when IFS does not contain whitespaces. This becomes problem with `${dict_options+"${dict_options[@]}"}`. One way to fix it is to set IFS=$' \t\n'. In this patch, we instead change the use of the array so that we do not have to rely on the ${v+"$@"} pattern. --- completions/dict | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/completions/dict b/completions/dict index eefb80ed97e..f3b0cb63c3e 100644 --- a/completions/dict +++ b/completions/dict @@ -14,7 +14,7 @@ _comp_cmd_dict() local cur prev words cword comp_args _comp_initialize -- "$@" || return - local -a dict_options=() + local -a dict_command=("$1") local host="" port="" db i local noargopts='!(-*|*[hpdis]*)' @@ -23,15 +23,15 @@ _comp_cmd_dict() case ${words[i]} in --host | -${noargopts}h) host=${words[++i]} - [[ $host ]] && dict_options+=(-h "$host") + [[ $host ]] && dict_command+=(-h "$host") ;; --port | -${noargopts}p) port=${words[++i]} - [[ $port ]] && dict_options+=(-p "$port") + [[ $port ]] && dict_command+=(-p "$port") ;; --database | -${noargopts}d) db=${words[++i]} - [[ $db ]] && dict_options+=(-d "$db") + [[ $db ]] && dict_command+=(-d "$db") ;; esac done @@ -44,11 +44,11 @@ _comp_cmd_dict() # shellcheck disable=SC2254 case $prev in --database | -info | -${noargopts}[di]) - _comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -D + _comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -D return ;; --strategy | -${noargopts}s) - _comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -S + _comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -S return ;; esac