Open daurnimator opened 3 years ago
It is not currently possible.
Some libraries support it with a special hidden command that takes the shell command line and prints a list of completions.
Then generated completion scripts would invoke e.g. mycommand __complete '--profile '
to get a list of completions.
That's what Cobra (Go) does: __complete
command, generated completion script.
Clang does something similar: http://blog.llvm.org/2017/09/clang-bash-better-auto-completion-is.html.
Some libraries support it with a special hidden command that takes the shell command line and prints a list of completions. Then generated completion scripts would invoke e.g.
mycommand __complete '--profile '
to get a list of completions.
Cool; I figured as much.
I guess we should add it as a special option to the existing completion subcommand/option?
I think you'd need to pass any current contexts (e.g. subcommands, other existing arguments that might filter down the output)
e.g. mycommand completion --complete-this='"mycommand","somesubcommand","--profile"'
@daurnimator If you are interested unifying in shell completion, there was an attempt to define a DSL which could be simplified by stripping regex and counting/loops: https://gitlab.redox-os.org/AdminXVII/shellac-server/-/tree/next
Portable context-aware autocompletion (the shell is asking what currently can be completed) requires an ABI-extension at POSIX-level, but I dont see interest to fix the shortcomings of posix shell so this will not happen.
Is it possible to create dynamic shell completions? e.g. if I type
mycommand --profile <TAB>
, can I provide a way to get a list of available profiles?If not, we should make that possible...
@pauloue