Parent directory

rust.plugin.zsh

902 bytes
 1if ! (( $+commands[rustup] && $+commands[cargo] )); then
 2  return
 3fi
 4
 5# If the completion file doesn't exist yet, we need to autoload it and
 6# bind it to `cargo`. Otherwise, compinit will have already done that
 7if [[ ! -f "$ZSH_CACHE_DIR/completions/_cargo" ]]; then
 8  autoload -Uz _cargo
 9  typeset -g -A _comps
10  _comps[cargo]=_cargo
11fi
12
13# If the completion file doesn't exist yet, we need to autoload it and
14# bind it to `rustup`. Otherwise, compinit will have already done that
15if [[ ! -f "$ZSH_CACHE_DIR/completions/_rustup" ]]; then
16  autoload -Uz _rustup
17  typeset -g -A _comps
18  _comps[rustup]=_rustup
19fi
20
21# Generate completion files in the background
22rustup completions zsh >| "$ZSH_CACHE_DIR/completions/_rustup" &|
23cat >| "$ZSH_CACHE_DIR/completions/_cargo" <<'EOF'
24#compdef cargo
25source "$(rustup run ${${(z)$(rustup default)}[1]} rustc --print sysroot)"/share/zsh/site-functions/_cargo
26EOF