How to make python argcomplete run with PowerShell

Viewed 432

I am trying to see if I can use argument autocompletion in Windows Powershell for my python script. Powershell allegedly supports argument completion.

Here's a minimal example which does not work:

#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK


import argparse
import argcomplete
from argcomplete.completers import EnvironCompleter


def argument_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description="Minimal app where arcomplete should work")
    parser.add_argument("--version", action="store_true", help="print out version").completer = EnvironCompleter
    parser.add_argument("--do-this", action="store_true", help="do this").completer = EnvironCompleter
    parser.add_argument("--do-that", action="store_true", help="do that").completer = EnvironCompleter
    return parser


if __name__ == "__main__":
    parser = argument_parser()
    argcomplete.autocomplete(parser)
    cli_args = parser.parse_args()

Then in Powershell I try: to type python -i minimal - and then press <TAB>, Nothing happens. What am I doing wrong? Maybe I should mention that I did not enable global autocompletion. Somehow when I run activate-global-python-argcomplete in powershell, I get an "Open With ..." dialogue.

0 Answers
Related