Add better bash_completion with the argcomplete package #672
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.
The current bash_completion script is very basic and the completion breaks after entering the first letter of a core name.
Since fusesoc uses the argparse package for argument parsing, we can use the argcomplete package for bash_completion.
Most of the completion is done automatically by argcomplete using the argparse parser. So there is no need to replicate argument/subparser names in a separate bash_completion file.
I also implemented completion for cores, generators and tools for the specific arguments.
Completion for bash/zsh can be enabled either globally or on a per-command basis.
Global completion can be enabled with the activate-global-python-argcomplete command. Additionally, the fusesoc binary needs the string PYTHON_ARGCOMPLETE_OK in the first 1024 bytes. I would have added this feature to the binary, but i can't find it in the repository. So it is not part of this pull request.
To enable completion for the fusesoc binary only, use the eval "$(register-python-argcomplete fusesoc)" command.
Completion can also be used unofficially with other shells (e.g. powershell).
The disadvantage of this approach is that it adds the argcomplete package as a dependency. However, the argcomplete package seems to be well maintained and is part of the repository of many Linux distributions.