Set up shell command-line tab-completion for jupyter and subcommands #337
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Set up shell command-line tab-completion using
argcomplete
and ipython/traitlets#811. Completion requiresargcomplete
to be activated andtraitlets>=5.8
. Behavior is only changed when$_ARGCOMPLETE
is set, so there should be no difference in behavior otherwise.For subcommand handling, this will use
list_subcommands()
to try to complete the first argument if it doesn't start with a "-", and when a subcommand is detected,argcomplete
will increment the start of the command-line handling past the subcommand and drop into the relevanttraitlets.Application
's argcomplete handling. All of the major subcommands likejupyter lab
directly usetraitlets.Application.launch_instance
so this works pretty seamlessly. However, completing commands that start with the hyphenated commands, e.g.jupyter-lab
, would still require the addition of thePYTHON_ARGCOMPLETE_OK
marker in the respective projects' main scripts. Note that argcomplete supports following setuptoolsconsole_scripts
to the corresponding main script to look for thePYTHON_ARGCOMPLETE_OK
marker.Example: