Watson icon indicating copy to clipboard operation
Watson copied to clipboard

Automatically generate bash completions

Open MaxG87 opened this issue 6 years ago • 4 comments

The current bash.completion is a bit of a second class citizen. Many of the current enhancements missed to adapt it. Furthermore, there are no tests for it.

Instead of trying to maintain this quite complex piece of software, one could try to generate completions from the click command line argument parsing framework. It seems to be possible to do so (https://click.palletsprojects.com/en/7.x/bashcomplete/).

Wouldn't it be great do drop bash.completion (and other completions) and reuse the implementation of the argument parsing?

MaxG87 avatar Apr 05 '19 22:04 MaxG87

This is probably a good idea! We should test it.

jmaupetit avatar Apr 09 '19 08:04 jmaupetit

I will try to get my hands dirty on this. Unfortunately, it might take some weeks.

MaxG87 avatar Apr 10 '19 22:04 MaxG87

Take your time! :pray:

jmaupetit avatar Apr 11 '19 08:04 jmaupetit

I managed to get it working. Actually, it seems to be very easy.

First, make sure to disable the current tab completion in order to see the effect. This might be done e.g. by

# sudo rm /etc/bash_completion.d/watson

I commented that line to prevent accidentally deletions.

Then one needs a new Bash. In this, one only has to execute

eval "$(_WATSON_COMPLETE=source watson)"

. This will automatically create a bash completion script and executes it. By this bash completion will be activated for the current shell. I would appreciate very much if someone else could double check enabling bash completion using this way.

The generated bash completion is not (yet) identical to the hand written one. Especially, it is missing completions for tags and projects.

In my humble opinion, this should be the way to go. Using the capabilities of the click framework will drop a maintenance burden and provide a consistent tab-completion experience over all subcommands. There might be some work to do in order to tab-complete projects, tags and maybe other information, but this seems to be easily done and highly justified to me.

MaxG87 avatar Apr 25 '19 23:04 MaxG87