Proposal: Better shell completions · Issue #6645 · rust-lang/cargo (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Description
This is a proposal to add better shell completion support to Cargo. The outline of the strategy is:
- Add a
cargo completions
subcommand to assist with completion support. cargo completions <shell>
will output a completion script for the given shell (bash, zsh, etc.).- The completion script will execute
cargo completions
to implement the work of actually emitting completions. This can significantly simplify the work of supporting completions for different shells. The completion script is very small (seenpm completion
for an example). This also means all the logic can be written in one language (Rust) and can be more easily tested.
Benefits:
- Support richer completions (such as
--bin
or--example
completing the target name). - Maintain consistent completions across shells.
- Easier to test.
- (Maybe) easier to keep in sync with clap.
- More easily discoverable (who knows the completions even exist?).
- Completions automatically stay in sync with the release via rustup.
Drawbacks:
- More stuff to maintain.
- Minor performance drawback compared to native-shell code. Many of the existing completions already execute commands, so in many cases it is a wash. Cargo's launch speed isn't terrible (~50ms for me).
- Won't be backwards compatible with older versions of Cargo.
Please let me know if you have any thoughts or objections.