kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

Global completion is not compatible with "time" #376

Open FurcyPin opened 1 year ago

FurcyPin commented 1 year ago

First, thanks for making this project, it's super useful :-)

Bug description

It looks like the global completion does not work for command line that start with the "time" command. This would not a big deal if not for the fact that once the autocomplete breaks on a command that starts with "time", it seems to remain broken for all commands until the terminal is restarted.

How to reproduce

With global completion enabled, I tried to autocomple the command activate-global-python-argcomplete, whic gave me a list of options:

$ activate-global-python-argcomplete -<TAB>
--complete-arguments  --dest                -h                    --help                --no-defaults         --user

When I tried the same with time prepended, nothing happens

$ time activate-global-python-argcomplete -<TAB>
# nothing

When I try again the first command that previously worked, it remains broken

$ activate-global-python-argcomplete -<TAB>
# nothing

Even if I run other commands or hit CTRL+C, the autocompletion seems to remain broken until I restart the terminal.

algorythmic commented 1 year ago

Completion for time is handled by _comp_command in bash-completion, with the goal of completing whatever command follows time.

In your case, the command is activate-global-python-argcomplete, for which there is no completion loaded, so bash-completion tries to find one and, when it fails, it registers the _minimal completion function for it.

Next time you try completing activate-global-python-argcomplete this newly registered _minimal function is what's called, bypassing the default _python_argcomplete_global function.

One thing that could help is if _python_argcomplete_global registered _python_argcomplete as the completion function for commands it ends up completing (which would also speed up completion next time it is attempted). However, this only helps in cases like yours where you first complete the command at least once and only after complete time.