2
0

asdf.plugin.zsh 922 B

123456789101112131415161718192021222324252627282930
  1. # Find where asdf should be installed
  2. ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}"
  3. ASDF_COMPLETIONS="$ASDF_DIR/completions"
  4. if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/_asdf" ]]; then
  5. # If not found, check for archlinux/AUR package (/opt/asdf-vm/)
  6. if [[ -f "/opt/asdf-vm/asdf.sh" ]]; then
  7. ASDF_DIR="/opt/asdf-vm"
  8. ASDF_COMPLETIONS="$ASDF_DIR"
  9. # If not found, check for Homebrew package
  10. elif (( $+commands[brew] )); then
  11. _ASDF_PREFIX="$(brew --prefix asdf)"
  12. ASDF_DIR="${_ASDF_PREFIX}/libexec"
  13. ASDF_COMPLETIONS="${_ASDF_PREFIX}/share/zsh/site-functions"
  14. unset _ASDF_PREFIX
  15. else
  16. return
  17. fi
  18. fi
  19. # Load command
  20. if [[ -f "$ASDF_DIR/asdf.sh" ]]; then
  21. source "$ASDF_DIR/asdf.sh"
  22. # Load completions
  23. if [[ -f "$ASDF_COMPLETIONS/_asdf" ]]; then
  24. fpath+=("$ASDF_COMPLETIONS")
  25. autoload -Uz _asdf
  26. compdef _asdf asdf # compdef is already loaded before loading plugins
  27. fi
  28. fi