Skip to content

Proposal: Better shell completions #6645

Open
@ehuss

Description

@ehuss

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 (see npm 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionsArea: shell completionsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions