// ZSH-CARGO-COMPLETION — LIVE CRATES.IO COMPLETION FOR cargo add / cargo install

zsh plugin · ships every OMZ cargo completion · live cargo search-backed completer for remote crate names

GitHub Issues
// Color scheme

>_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

baseco = cargo
run / build / releasecr, cb, cbr
test / clippy / fmt / fixct, ccy, cfm, cfi
add / install / install-update / search / fetchcad, ci, ciu, cs, cfe
package / publish / cleancpa, 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 namescargo add ran<TAB> / cargo install <TAB> — queries crates.io live via cargo search
subcommandscargo <TAB> — parsed from cargo --list, so custom cargo-* subcommands appear automatically
per-subcommand flags32 subcommands have their own flag tables (cargo build --<TAB>, cargo test --<TAB>, ...)
installed binariescargo uninstall <TAB> — from cargo install --list
example targetscargo run --example <TAB> — from examples/*.rs
nightly flagscargo -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 completionConfirm cargo search serde works on its own; the completer shells out to exactly that command. A failing/proxied network means no candidates.
completion not loadingEnsure 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 listThe per-prefix cache persists across sessions when use-cache is on. Remove $HOME/.zcompcache/crate_*_cache to force a fresh cargo search.
alias conflictsSeveral 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: