asdf.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. if (( $+commands[asdf] )); then
  2. export ASDF_DATA_DIR="${ASDF_DATA_DIR:-$HOME/.asdf}"
  3. path=("$ASDF_DATA_DIR/shims" $path)
  4. # If the completion file doesn't exist yet, we need to autoload it and
  5. # bind it to `asdf`. Otherwise, compinit will have already done that.
  6. if [[ ! -f "$ZSH_CACHE_DIR/completions/_asdf" ]]; then
  7. typeset -g -A _comps
  8. autoload -Uz _asdf
  9. _comps[asdf]=_asdf
  10. fi
  11. asdf completion zsh >| "$ZSH_CACHE_DIR/completions/_asdf" &|
  12. return
  13. fi
  14. # TODO:(2025-02-12): remove deprecated asdf <0.16 code
  15. # Find where asdf should be installed
  16. ASDF_DIR="${ASDF_DIR:-$HOME/.asdf}"
  17. ASDF_COMPLETIONS="$ASDF_DIR/completions"
  18. if [[ ! -f "$ASDF_DIR/asdf.sh" || ! -f "$ASDF_COMPLETIONS/_asdf" ]]; then
  19. # If not found, check for archlinux/AUR package (/opt/asdf-vm/)
  20. if [[ -f "/opt/asdf-vm/asdf.sh" ]]; then
  21. ASDF_DIR="/opt/asdf-vm"
  22. ASDF_COMPLETIONS="$ASDF_DIR"
  23. # If not found, check for Homebrew package
  24. elif (( $+commands[brew] )); then
  25. _ASDF_PREFIX="$(brew --prefix asdf)"
  26. ASDF_DIR="${_ASDF_PREFIX}/libexec"
  27. ASDF_COMPLETIONS="${_ASDF_PREFIX}/share/zsh/site-functions"
  28. unset _ASDF_PREFIX
  29. else
  30. return
  31. fi
  32. fi
  33. # Load command
  34. if [[ -f "$ASDF_DIR/asdf.sh" ]]; then
  35. source "$ASDF_DIR/asdf.sh"
  36. # Load completions
  37. if [[ -f "$ASDF_COMPLETIONS/_asdf" ]]; then
  38. fpath+=("$ASDF_COMPLETIONS")
  39. autoload -Uz _asdf
  40. compdef _asdf asdf # compdef is already loaded before loading plugins
  41. fi
  42. fi