Skip to content

Commit

Permalink
Merge pull request #971 from akinomyoga/_parse_help-3
Browse files Browse the repository at this point in the history
refactor: remaining `_comp_compgen_{help,usage}` changes
  • Loading branch information
scop authored May 9, 2023
2 parents 3b50c6d + 309dec7 commit a17197f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions completions/_hwclock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion completions/badblocks
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions completions/dnssec-keygen
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ _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 '"${COMPREPLY[@]%:}"'
return
fi
} &&
Expand Down
4 changes: 2 additions & 2 deletions completions/jps
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions completions/links
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ _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 '"${COMPREPLY[@]}"' -X "->"
return
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/ps
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions completions/puppet
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
;;
Expand Down
4 changes: 2 additions & 2 deletions completions/tar
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions completions/zopfli
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ _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 '"${COMPREPLY[@]%#}"'
[[ ${COMPREPLY-} == --i ]] && compopt -o nospace
return
fi
Expand Down

0 comments on commit a17197f

Please sign in to comment.