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