rust.plugin.zsh 1.1 KB

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