>_ZSH-CARGO-COMPLETION
Cargo completion with a live remote index. Every OMZ cargo completion plus a live cargo search-backed completer for cargo add and cargo install. Type cargo add <TAB> and the remote crates.io index is queried in real time.
Install
# Zinit (recommended)
zinit ice lucid nocompile
zinit load MenkeTechnologies/zsh-cargo-completion
# Oh My Zsh
git clone https://github.com/MenkeTechnologies/zsh-cargo-completion \
"$HOME/.oh-my-zsh/custom/plugins/zsh-cargo-completion"
# then: plugins+=(zsh-cargo-completion)
# Manual
git clone https://github.com/MenkeTechnologies/zsh-cargo-completion
source zsh-cargo-completion/zsh-cargo-completion.plugin.zsh
Aliases
| base | co = cargo |
| run / build / release | cr, cb, cbr |
| test / clippy / fmt / fix | ct, ccy, cfm, cfi |
| add / install / install-update / search / fetch | cad, ci, ciu, cs, cfe |
| package / publish / clean | cpa, cpl, ccl |
The full alias table is in the README "ALIASES" section.
What gets completed
Three layers, all via zsh's native completion system (compsys) — no daemon, no background process:
| remote crate names | cargo add ran<TAB> / cargo install <TAB> — queries crates.io live via cargo search |
| subcommands | cargo <TAB> — parsed from cargo --list, so custom cargo-* subcommands appear automatically |
| per-subcommand flags | 32 subcommands have their own flag tables (cargo build --<TAB>, cargo test --<TAB>, ...) |
| installed binaries | cargo uninstall <TAB> — from cargo install --list |
| example targets | cargo run --example <TAB> — from examples/*.rs |
| nightly flags | cargo -Z <TAB> — from cargo -Z help |
Examples
cargo add <TAB> # live crate name completion from crates.io cargo add ran<TAB> # narrows to crates whose name matches the prefix cargo install <TAB> # same remote completer cargo <TAB> # subcommand list from `cargo --list` cargo build --<TAB> # build-specific flags only cargo test --features <TAB> cargo uninstall <TAB> # installed binary crates cargo -Z <TAB> # nightly unstable flags cad ser # add serde via the cad alias cs serde # `cargo search serde` via the cs alias
Configuration
The remote completer caches per prefix in two tiers: an in-session zsh parameter (__crate_<prefix>) and the standard on-disk completion cache backing _retrieve_cache / _store_cache. The on-disk tier obeys zsh's normal completion-cache styles — set these in ~/.zshrc before compinit:
# enable the on-disk completion cache (off by default in zsh) zstyle ':completion:*' use-cache yes zstyle ':completion:*' cache-path "$HOME/.zcompcache"
Load order matters: source this plugin so that ${0:h}/src is on fpath before compinit runs. Under Oh My Zsh and Zinit this is handled automatically by the plugin file's fpath prepend. The flag guard (cargo add --<TAB>) skips the network call entirely — the live lookup only fires when the word under the cursor is a crate-name prefix.
Troubleshooting
| no remote completion | Confirm cargo search serde works on its own; the completer shells out to exactly that command. A failing/proxied network means no candidates. |
| completion not loading | Ensure compinit runs after the plugin is sourced. Under Zinit, use nocompile so ${0:h}/src resolves to the on-disk src/ rather than a compiled .zwc. |
| stale crate list | The per-prefix cache persists across sessions when use-cache is on. Remove $HOME/.zcompcache/crate_*_cache to force a fresh cargo search. |
| alias conflicts | Several aliases (co, cr, cb, ct, ...) overlap with the OMZ rust/cargo plugins. Load this plugin last so its aliases win. |
Sibling plugins
Part of the MenkeTechnologies zsh plugin family — the MenkeTechnologiesMeta umbrella:
- zsh-better-npm-completion — cache-aware
npm installcompletion - zsh-cpan-completion — live MetaCPAN
cpan/cpanmcompletion - zsh-dotnet-completion — dotnet CLI completion
- zsh-expand — spacebar expansion (11,683 tests)
- zsh-gem-completion — ruby
gem installremote completion - zsh-git-acp — 159 git aliases + add/commit/push keybindings
- zsh-git-repo-cache — index every git repo on disk
- zsh-learn — MySQL-backed learning collection / quiz
- zsh-more-completions — 33,175-file mega completion corpus
- zsh-nginx — nginx commands + service-wrapper aliases
- zsh-pip-description-completion — pip remote completion with descriptions
- zsh-sed-sub — in-place sed substitution on the command line
- zsh-sudo — ESC ESC to prepend sudo
- zsh-xcode-completions — xcodebuild / xcrun / swift completion