iterative / shtab

↔️ Automagic shell tab completion for Python CLI applications
https://docs.iterative.ai/shtab
Other
362 stars 35 forks source link

Completion of environment variable names #172

Open mauvilsa opened 2 months ago

mauvilsa commented 2 months ago

When working in shells it is common to store values in environment variables, and most commands allow tab completion of environment variable names, for example:

$ echo $BASH_V<TAB>
$ echo $BASH_VERSI<TAB><TAB>
$BASH_VERSINFO  $BASH_VERSION
$ echo $BASH_VERSIO<TAB>
$ echo $BASH_VERSION

Unfortunately, when an shtab completion script is activated, the completion of environment variable names doesn't work. For instance take the following script:

from argparse import ArgumentParser
import shtab

parser = ArgumentParser()
parser.add_argument("--pid", type=int)
shtab.add_argument_to(parser, "--shell-completion")
print(parser.parse_args())

The following doesn't complete anything:

$ cli.py --pid $BASHP<TAB><TAB>