Skip to content

Bash completion for arguments not working #628

@xificurC

Description

@xificurC

Option arguments don't seem to show up after hitting tabs after a dash, while the documentation says option arguments get completed. Here is a stripped down example:

$ cd test
$ virtualenv .test
$ . ./.test/bin/activate
$ cat tester.py

import click

@click.command()
@click.option('--hi', help='hi')
def cli(hi):
    click.echo(hi)

$ cat setup.py

from setuptools import setup

setup(
    name = 'tester',
    version = '0.1',
    py_modules = ['tester'],
    install_requires = [
        'Click',
    ],
    entry_points = """
    [console_scripts]
    tester=tester:cli
    """,
)

$ pip install --editable .
$ _TESTER_COMPLETE=source tester > tester-complete.sh
$ . tester-complete.sh
$ tester --<TAB><TAB> <-- doesn't show the hi option.

$ python --version
Python 3.4.3

$ pip list | grep click
click (6.6)

$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

$ cat tester-complete.sh

_tester_completion() {
    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   _TESTER_COMPLETE=complete $1 ) )
    return 0
}

complete -F _tester_completion -o default tester;

The command otherwise works fine.
$ tester --help

Usage: tester [OPTIONS]

Options:
  --hi TEXT  hi
  --help     Show this message and exit.

$ tester --hi there
there

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions