I'm wanting to customize the BASH completion functionality of my Python Click CLI program to include not only the commands / subcommands of the script, but also objects that the script creates.
Let's say my program is called cli-tool
, and it can create object foo
using the command:
cli-tool object create foo
For simplicity, let's say the command simply concatenates the argument string (foo
in this case) to a text file of the same name located in ~/.cli-tool/objects/foo
. Doing cat ~/.cli-tool/objects/foo
would then print foo
in your terminal.
What I would like for the tool to do is when I then type:
cli-tool object get <TAB><TAB>
The terminal would then list foo
and any other files that live inside ~/.cli-tool/objects
.
For the record, I have read the Python Click 6.x stable documentation, which clearly states:
Currently, Bash completion is an internal feature that is not customizable. This might be relaxed in future versions.
What I was hoping is that there would be a way to extract the full BASH completion script from the following command:
eval "$(_CLI_TOOL_COMPLETE=source cli-tool)"
And then customize it myself. I've also seen the click-completion project, but I'm not sure what it does beyond extending the completion for Zsh and Fish shells.
Has anyone achieved the type of completion I mention above?