]> git.tuebingen.mpg.de Git - gsu.git/commitdiff
Fix gsu com_complete().
authorAndre Noll <maan@systemlinux.org>
Tue, 29 Nov 2011 13:02:48 +0000 (14:02 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 29 Aug 2014 19:39:58 +0000 (21:39 +0200)
It should work also if set -u was given. Currently this fails if
_com_complete() is called with no arguments.

Moreover, the first argument, if it is provided, should be a number
but we missed to check this.

misc/gsu/subcommand

index 911179eb45eb57590dbb0b4f4f484e2ecb86f2c5..7ba4850b66baf62b34f5a5c1db7c47e48c50c641 100644 (file)
@@ -400,7 +400,7 @@ gsu_getopts()
 
 _com_complete()
 {
 
 _com_complete()
 {
-       local cmd n cword="$1"
+       local cmd n cword
        local -a words
 
        if (($# == 0)); then
        local -a words
 
        if (($# == 0)); then
@@ -411,9 +411,13 @@ _com_complete()
                candidates=(\$($0 complete "\$COMP_CWORD" "\${COMP_WORDS[@]}"));
                COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
 EOF
                candidates=(\$($0 complete "\$COMP_CWORD" "\${COMP_WORDS[@]}"));
                COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
 EOF
+               ret=$GSU_SUCCESS
+               return
        fi
 
        fi
 
-       [[ -z "$cword" ]] && return
+       cword="$1"
+       gsu_is_a_number "$cword"
+       (($ret < 0)) && return
        if (($cword <= 1)); then
                _gsu_available_commands
                echo "${result}"
        if (($cword <= 1)); then
                _gsu_available_commands
                echo "${result}"