Skip to content

Short option autocompleted with an extra equal sign (Bash) #14

@born4new

Description

@born4new

Here is my test program:

Usage:
  #{__FILE__} [--test=<test-value>]
  #{__FILE__} -h | --help | --version

Options:
  -h, --help               Shows this screen.
  -v, --version            Display the program version.
  -t, --test <test-value>  My own test value

Here are some use-cases for the above program (I'm using docopt.rb here):

# Valid case: long option with equals sign
./docopt-test.rb --test=1234

# Output
{"--test"=>"1234", "--help"=>false, "--version"=>false}

# Valid case: short option with a space
./docopt-test.rb -t 1234

# Output
{"--test"=>"1234", "--help"=>false, "--version"=>false}

# Invalid case: short option with an equal sign
./docopt-test.rb -t=1234

# Output (the value is =1234 here)
{"--test"=>"=1234", "--help"=>false, "--version"=>false}

Here is the autocomplete file I get when using this tool:

_docopttestrb()
{
    local cur
    cur="${COMP_WORDS[COMP_CWORD]}"

    if [ $COMP_CWORD -ge 1 ]; then
        COMPREPLY=( $( compgen -W '-t= --test= -h --help -h --help -v --version ' -- $cur) )
    fi
}

complete -o bashdefault -o default -o filenames -F _docopttestrb docopt-test.rb

It basically only autocompletes with -t=, which is an invalid option as far as docopt is concerned.

Is this a problem on my script or could this be a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions