2021-12-28 10:42:17 +00:00
|
|
|
if ! (( $+commands[rustup] && $+commands[cargo] )); then
|
|
|
|
return
|
|
|
|
fi
|
2021-09-15 16:41:44 +00:00
|
|
|
|
2021-12-28 10:42:17 +00:00
|
|
|
# Remove old generated completion file
|
|
|
|
# TODO: 2021-09-15: remove this line
|
|
|
|
command rm -f "${0:A:h}/_cargo"
|
2021-09-15 16:18:25 +00:00
|
|
|
|
2021-12-28 10:42:17 +00:00
|
|
|
# Add completions/ folder in $ZSH_CACHE_DIR
|
|
|
|
comp_file="$ZSH_CACHE_DIR/completions/_cargo"
|
|
|
|
command mkdir -p "${comp_file:h}"
|
|
|
|
(( ${fpath[(Ie)"$ZSH_CACHE_DIR/completions"]} )) || fpath=("$ZSH_CACHE_DIR/completions" $fpath)
|
2021-09-15 16:18:25 +00:00
|
|
|
|
2021-12-28 10:42:17 +00:00
|
|
|
# If the completion file doesn't exist yet, we need to autoload it and
|
|
|
|
# bind it to `cargo`. Otherwise, compinit will have already done that
|
|
|
|
if [[ ! -f "$comp_file" ]]; then
|
2021-09-07 18:02:20 +00:00
|
|
|
autoload -Uz _cargo
|
2021-12-28 10:42:17 +00:00
|
|
|
declare -A _comps
|
2021-09-07 18:02:20 +00:00
|
|
|
_comps[cargo]=_cargo
|
|
|
|
fi
|
2021-12-28 10:42:17 +00:00
|
|
|
|
|
|
|
# Generate completion file in the background
|
|
|
|
rustup completions zsh cargo >| "$comp_file" &|
|
|
|
|
unset comp_file
|