From a286e4f13759b52a4c1bddd799c4c0bcb3a28287 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 1 May 2023 22:28:57 +0900 Subject: [PATCH 1/4] refactor: use _comp_compgen_help with post-filter --- completions/badblocks | 4 +++- completions/dnssec-keygen | 6 ++++-- completions/links | 6 ++++-- completions/zopfli | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/completions/badblocks b/completions/badblocks index df84e280cc8..14e4e05ee83 100644 --- a/completions/badblocks +++ b/completions/badblocks @@ -17,7 +17,9 @@ _comp_cmd_badblocks() if [[ $cur == -* ]]; then # Filter out -w (dangerous) and -X (internal use) - COMPREPLY=($(compgen -X '-[wX]' -W '$(_parse_usage "$1")' -- "$cur")) + _comp_compgen -R usage + ((${#COMPREPLY[@]})) && + _comp_compgen -- -X '-[wX]' -W '"${COMPREPLY[@]}"' return fi diff --git a/completions/dnssec-keygen b/completions/dnssec-keygen index 4685af23786..a2b325f0edc 100644 --- a/completions/dnssec-keygen +++ b/completions/dnssec-keygen @@ -37,8 +37,10 @@ _comp_cmd_dnssec_keygen() esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1" | \ - command sed -e "s/:\$//")' -- "$cur")) + _comp_compgen -R help + ((${#COMPREPLY[@]})) && + _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | + command sed -e "s/:\$//")' return fi } && diff --git a/completions/links b/completions/links index ea14d6ddc89..7c7f49eed47 100644 --- a/completions/links +++ b/completions/links @@ -80,8 +80,10 @@ _comp_cmd_links() esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1" | - command grep -vF -- "->")' -- "$cur")) + _comp_compgen -R help + ((${#COMPREPLY[@]})) && + _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | + command grep -vF -- "->")' return fi diff --git a/completions/zopfli b/completions/zopfli index 6da30a32a63..f948ec12a14 100644 --- a/completions/zopfli +++ b/completions/zopfli @@ -12,8 +12,10 @@ _comp_cmd_zopfli() esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W \ - '$(_parse_help "$1" -h | command sed -e "s/#$//")' -- "$cur")) + _comp_compgen -R help -- -h + ((${#COMPREPLY[@]})) && + _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | + command sed -e "s/#$//")' -- "$cur" [[ ${COMPREPLY-} == --i ]] && compopt -o nospace return fi From dfb1a88e2246c43406429b05c71db8a39a757015 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 1 May 2023 22:30:15 +0900 Subject: [PATCH 2/4] refactor(_hwclock): use _comp_compgen_help --- completions/_hwclock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/_hwclock b/completions/_hwclock index 82619ee0363..a0fd8315288 100644 --- a/completions/_hwclock +++ b/completions/_hwclock @@ -18,8 +18,8 @@ _comp_cmd_hwclock() ;; esac - COMPREPLY=( - $(PATH="$PATH:/sbin" compgen -W '$(_parse_help "$1")' -- "$cur")) + local PATH=$PATH:/sbin + _comp_compgen_help } && complete -F _comp_cmd_hwclock hwclock From 95e16ffa51980b56e8f0e5ec19c803d713a7b657 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 1 May 2023 22:36:48 +0900 Subject: [PATCH 3/4] refactor: update `_parse_{help,usage}` in code comments --- completions/jps | 4 ++-- completions/ps | 2 +- completions/puppet | 6 ++++-- completions/tar | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/completions/jps b/completions/jps index f90ab7eaafc..be5b8d62151 100644 --- a/completions/jps +++ b/completions/jps @@ -12,8 +12,8 @@ _comp_cmd_jps() esac if [[ $cur == -* ]]; then - # Not using _parse_usage because output has [-help] which does not - # mean -h, -e, -l, -p... + # Not using _comp_compgen_usage because output has [-help] which does + # not mean -h, -e, -l, -p... _comp_compgen -- -W "-q -m -l -v -V -J -help" [[ ${COMPREPLY-} == -J* ]] && compopt -o nospace else diff --git a/completions/ps b/completions/ps index 1a7e2901005..d32083ecea4 100644 --- a/completions/ps +++ b/completions/ps @@ -56,7 +56,7 @@ _comp_cmd_ps() esac if [[ $cur == -* ]]; then - # sed: strip single char dashless ", x," that trip _parse_help + # sed: strip single char dashless ", x," that trip _comp_compgen_help _comp_compgen_help - <<<"$({ "$1" --help "$1" --help all diff --git a/completions/puppet b/completions/puppet index fbf5eeba045..91b8341e719 100644 --- a/completions/puppet +++ b/completions/puppet @@ -147,7 +147,8 @@ _comp_cmd_puppet() ;; *) _comp_cmd_puppet__subcmd_opts "$1" "$subcommand" - # _parse_usage doesn't grok [-D|--daemonize|--no-daemonize] + # _comp_compgen_usage doesn't grok + # [-D|--daemonize|--no-daemonize] _comp_compgen -a -- -W '--no-daemonize' return ;; @@ -298,7 +299,8 @@ _comp_cmd_puppet() ;; *) _comp_cmd_puppet__subcmd_opts "$1" "$subcommand" - # _parse_usage doesn't grok [-D|--daemonize|--no-daemonize] + # _comp_compgen_usage doesn't grok + # [-D|--daemonize|--no-daemonize] _comp_compgen -a -- -W '--no-daemonize' return ;; diff --git a/completions/tar b/completions/tar index 2c35491a68c..47d02f69ffb 100644 --- a/completions/tar +++ b/completions/tar @@ -19,8 +19,8 @@ # ------------------------- # # For GNU tar, everything is parsed from `tar --help` output so not so much -# per-distribution work should be needed. The _parse_help does not seem to be -# good enough so parsed here directly. +# per-distribution work should be needed. The _comp_compgen_help does not seem +# to be good enough so parsed here directly. # # # FIXME: --starting-file (-K) (should be matched for extraction only) From 309dec7c007b894cfc3100213a88731c6735d3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 10 May 2023 02:54:34 +0900 Subject: [PATCH 4/4] refactor(dnssec-keygen,links,zpofli): use builtin feat for filtering --- completions/dnssec-keygen | 3 +-- completions/links | 3 +-- completions/zopfli | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/completions/dnssec-keygen b/completions/dnssec-keygen index a2b325f0edc..9db55b5a232 100644 --- a/completions/dnssec-keygen +++ b/completions/dnssec-keygen @@ -39,8 +39,7 @@ _comp_cmd_dnssec_keygen() if [[ $cur == -* ]]; then _comp_compgen -R help ((${#COMPREPLY[@]})) && - _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | - command sed -e "s/:\$//")' + _comp_compgen -- -W '"${COMPREPLY[@]%:}"' return fi } && diff --git a/completions/links b/completions/links index 7c7f49eed47..935cfa7816b 100644 --- a/completions/links +++ b/completions/links @@ -82,8 +82,7 @@ _comp_cmd_links() if [[ $cur == -* ]]; then _comp_compgen -R help ((${#COMPREPLY[@]})) && - _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | - command grep -vF -- "->")' + _comp_compgen -- -W '"${COMPREPLY[@]}"' -X "->" return fi diff --git a/completions/zopfli b/completions/zopfli index f948ec12a14..d7e3961d205 100644 --- a/completions/zopfli +++ b/completions/zopfli @@ -14,8 +14,7 @@ _comp_cmd_zopfli() if [[ $cur == -* ]]; then _comp_compgen -R help -- -h ((${#COMPREPLY[@]})) && - _comp_compgen -- -W '$(printf "%s\n" "${COMPREPLY[@]}" | - command sed -e "s/#$//")' -- "$cur" + _comp_compgen -- -W '"${COMPREPLY[@]%#}"' [[ ${COMPREPLY-} == --i ]] && compopt -o nospace return fi