2727# ########
2828#
2929
30- __argsparse_complete_printf () {
31- printf -- ' %s\n%s ' " $@ "
30+ __argsparse_compgen () {
31+ compgen " $@ " -- " $cur "
3232}
3333
3434__argsparse_complete_value () {
@@ -38,35 +38,35 @@ __argsparse_complete_value() {
3838 if array=$( __argsparse_values_array_identifier " $option " )
3939 then
4040 values=( ${! array} )
41- printf ' %s\n%s ' -W " ${values[*]} "
41+ __argsparse_compgen -W " ${values[*]} "
4242 elif option_type=$( argsparse_has_option_property " $option " type)
4343 then
4444 case " $option_type " in
4545 file|pipe|socket|link)
46- printf -- ' %s\n%s ' -A file
46+ __argsparse_compgen -A file
4747 ;;
4848 directory|group)
49- printf -- ' %s\n%s ' -A " $option_type "
49+ __argsparse_compgen -A " $option_type "
5050 ;;
5151 username)
52- printf -- ' %s\n%s ' -A user
52+ __argsparse_compgen -A user
5353 ;;
5454 host|hostname)
55- printf -- ' %s\n%s ' -A hostname
55+ __argsparse_compgen -A hostname
5656 ;;
5757 hexa)
5858 values=( " $cur " {a..f} )
5959 ;;&
6060 int|hexa)
6161 values+=( " $cur " {0..9} )
62- printf -- ' %s\n%s ' -W " ${values[*]} "
62+ __argsparse_compgen -W " ${values[*]} "
6363 ;;
6464 esac
6565 fi
6666}
6767
6868__argsparse_complete () {
69- local script=$1
69+ local script=${words[0]}
7070 (
7171 set +o posix
7272 ARGSPARSE_COMPLETION_MODE=1
@@ -85,7 +85,7 @@ __argsparse_complete() {
8585 shorts=( " ${shorts[@]/#/ -} " )
8686 ;;&
8787 " " |-* )
88- printf -- ' %s\n%s ' -W " ${shorts[*]} ${longs[*]} "
88+ __argsparse_compgen -W " ${shorts[*]} ${longs[*]} "
8989 ;;
9090 * )
9191 ;;
@@ -97,10 +97,7 @@ __argsparse_complete() {
9797_argsparse_complete () {
9898 local cur prev words cword split
9999 _init_completion -s || return
100- local complete_type complete_values
101- { read complete_type ; complete_values=$( < /dev/stdin) ; } \
102- < <( __argsparse_complete " ${words[0]} " )
103- COMPREPLY=( $( compgen " $complete_type " " $complete_values " -- " $cur " ) )
100+ COMPREPLY=( $( __argsparse_complete) )
104101}
105102
106103complete -F _argsparse_complete 1-basics 2-values 3-cumulative-options 4-types 5-custom-types 6-properties 7-value-checking 8-setting-hook 9-misc
0 commit comments