Open epage opened 1 month ago
This feature is undoubtedly a powerful capability. Let me try to explain my understanding of this feature.
For external subcommand completions, we can categorize them into cases that require forward completions and those that do not.
For cases that do not require forward completions, such as cargo <alias>
, this is simple to implement.
For cases that require forward completions, such as mycommand git [TAB]
, we need to address the following:
For external subcommand completions, we might need to clarify the type of subcommand. I categorize them into external commands implemented by clap and those not implemented by clap:
For external commands implemented by clap: We could potentially save some metadata in a special path, which might allow us to achieve shell-independent completions within clap itself. We might call COMPLETE=<shell> external_subcommand -- xx xx xx xx
to obtain completion results.
For external commands not implemented by clap: Their completions are necessarily shell-specific because we have no knowledge about how to complete them or what their completion scripts are like. We need to construct a new command-line input (excluding argv[0]) and then invoke some shell built-in commands (or write a script) to obtain completion results.
fish
complete --do-complete="<command line>"
could get the completion of <command line>
bash
We could reset COMP_LINE
, COMP_WORDS
, COMP_POINT
, COMP_CWORD
to get completions from COMPRELAY
There are also some other shells for which I am currently unsure how to implement this feature.
For cases that do not require forward completions, such as cargo
, this is simple to implement.
I view this as separate from this issue though it would be good to have a way to solve it.
For external commands implemented by clap:
imo users and other applications should not be aware an application is using clap
.
For external commands not implemented by clap:
This is likely what we'll need to do.
I put this as one of the lowest priority items. I do not believe it is needed for parity with existing clap_complete
or for cargo
.
cargo run
cargo <plugin>
and likely other cases require completing other commands.
See https://carapace-sh.github.io/carapace-bin/spec/embed.html