rust.plugin.zsh 892 B

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