Well, since I'm emulating bash to start, those completion scripts will support multiple shells :)
However, I recently learned that zsh also emulates bash, e.g. the complete/compgen/compopt builtins, along with some global variables. So that is already technically true.
Still, I'd like to define some kind of "nicer" protocol that binaries can implement to get completion.
But that also sort of exists: I learned that when you do "ls --<TAB>" in bash right now, the script actually dynamically greps "ls --help" for flags! This is in contrast to how ZSH works -- it has a bunch of canned completions, which presumably suffer from a version skew problem.
Someone out pointed out "npm completion" in this thread, which is new to me (try it; it prints a bash script).
git is also adding 'git --listcmds' to help with completion. So the logic is partially in the binary, and partially in the shell completion script.
I think I've seen other ad hoc mechanisms along those lines too. Ah yes I recall that there was XML output for the Google flag parser [1], which is meant to be used for completion, although I'm not sure how commonly it's used.
So basically there are a lot of different systems. Hoping that someone will come along and produce a universal solution is probably wishful thinking. It's another "boiling the ocean" problem.
I'd like to contribute to a project that would help me be able to write a CLI tool and have tab completions work across shells. The problem is that I don't have a good enough understanding of how tab completion currently works to even know where to start. Is it fair to say that you're having the same problem?
Yes I think that is a good problem to solve. I'm working in this area right now, although I wouldn't say cross-shell compatibility the specific problem I'm solving now.
I think what would be nice is to collect examples like 'git --listcmds' and 'npm completion'
(previously mentioned), i.e. places where the binary itself helps out with completion.
In those cases, more of the logic is shell-independent. It's not 100% and will never be, but it's nice to share as much as possible.
Also, it would nice to see other ways that commands support multiple shells. For example, git has both bash and zsh completion in its tree.
Though I'm pretty sure the zsh developers wrote their own completion that is much richer than the bash-like one in upstream.
I believe the problem is that "completion" in zsh has a higher standard. You can make a lowest-common-denominator solution already. I think that is OK for now, but zsh users might disagree.
I think the other popular interactive shell is fish (based on my survey), so I'd be interested in learning more about it. However I wouldn't underestimate the fact that probably 90% of people use bash.
Feel free to e-mail me if you want to talk about it more (address in profile), or you can chat with me here:
However, I recently learned that zsh also emulates bash, e.g. the complete/compgen/compopt builtins, along with some global variables. So that is already technically true.
Still, I'd like to define some kind of "nicer" protocol that binaries can implement to get completion.
But that also sort of exists: I learned that when you do "ls --<TAB>" in bash right now, the script actually dynamically greps "ls --help" for flags! This is in contrast to how ZSH works -- it has a bunch of canned completions, which presumably suffer from a version skew problem.
Someone out pointed out "npm completion" in this thread, which is new to me (try it; it prints a bash script).
git is also adding 'git --listcmds' to help with completion. So the logic is partially in the binary, and partially in the shell completion script.
I think I've seen other ad hoc mechanisms along those lines too. Ah yes I recall that there was XML output for the Google flag parser [1], which is meant to be used for completion, although I'm not sure how commonly it's used.
So basically there are a lot of different systems. Hoping that someone will come along and produce a universal solution is probably wishful thinking. It's another "boiling the ocean" problem.
[1] https://github.com/gflags/gflags