Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completion with python -m module_name without creating an explicit executable script? #178

Open
rameloni opened this issue Oct 9, 2024 · 0 comments

Comments

@rameloni
Copy link

rameloni commented Oct 9, 2024

I'm trying to enable auto-completion for Python scripts executed with python -m my_module -[TAB] [TAB] or python my_module.py -[TAB] [TAB].

I first created the script:

#!/usr/bin/env python3

import argparse

def get_main_parser():
    parser = argparse.ArgumentParser(prog="my_module")
    parser.add_argument("--a", default=None)
    parser.add_argument("--b", default=None)
    return parser


if __name__ == "__main__":
    parser = get_main_parser()
    args = parser.parse_args()
    print(args)

Then:

chmod +x ./my_module.py
alias my_module='./my_module.py'
eval "$(shtab --prog=my_module --shell=bash my_module.get_main_parser)"

And my_module -[TAB] [TAB] works but when I try python3 -m my_module -[TAB] [TAB] or python3 my_module.py -[TAB] [TAB] autocompletion doesn't work. I also tried to replace prog="my_module" with prog="my_module.py" but still it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant