I'd like to provide shell completions for all major shells for my program (I consider bash
, fish
and zsh
as major shells, but other ones can be considered).
I don't want to write them, I'd like them to be generated for me. How can I do that?
My research
Some argument handling libraries like Click provide options to generate shell completions. To my knowledge, Python, Go and Rust provide libraries for this. My program is in C++, so using these would require writing a stub program in one of these languages and using some argument handling library that provides completion generation. This can be troublesome, because the generated completions can depend on the original program. For example Click generated completions call the original Python program to get the options. This means that the stub program would have to be distributed along the completions for them to work.
Some programs (and even shells themselves) can generate completion from --help
messages. This is troublesome, because the format of help messages isn't really specified anywhere and this approach is not flexible at all.
Then there are programs that can generate completions from some sort of argument description. There are only a few of them. One of them is complgen for example. I don't find its argument specification syntax intuitive and Zsh completions are broken at the moment (fixed in master), but it is an option.