traitlets icon indicating copy to clipboard operation
traitlets copied to clipboard

Add support for bash completion to Application

Open telamonian opened this issue 6 years ago • 0 comments

A traitlets Application is able to accept various command line arguments. For aliases, flags, and subcommands, at least, I think it would make a lot of sense if traitlets provided an automatic (or at least easy) way to set up the related completions for bash (and possibly other shells). This would make an Application's command line arguments easier to enter, and also easier to discover.

I work a lot on JupyterLab core and the related ecosystem. My use case for this feature is so that I never have to fully type out

jupyter labextension install ...

ever again. I think this feature belongs in the traitlets package specifically since:

  • It makes the most sense to implement completion support adjacent to the command line argument handling
  • A general solution to this issue would be potentially of use to every project that uses Application

In the past, I've found that by far the simplest way to implement bash completion for a Python script is to use the argcomplete package. Given that a script is parsing cmd line args using the argparse standard lib package, you can set up bash completion with argcomplete by adding 3 lines to the script.

From skimming the code in traitlets/config/application.py and traitlets/config/loader.py it appears that at a low level traitlets is indeed using argparse to parse cmd line args (though please correct me if I'm wrong about that). So I'll take a stab at making a PR for this issue based on argcomplete.

telamonian avatar Nov 07 '19 05:11 telamonian