nvm.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # See https://github.com/nvm-sh/nvm#installation-and-update
  2. if [[ -z "$NVM_DIR" ]]; then
  3. if [[ -d "$HOME/.nvm" ]]; then
  4. export NVM_DIR="$HOME/.nvm"
  5. elif [[ -d "${XDG_CONFIG_HOME:-$HOME/.config}/nvm" ]]; then
  6. export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm"
  7. fi
  8. fi
  9. # Don't try to load nvm if command already available
  10. which nvm &> /dev/null && return
  11. if [[ -f "$NVM_DIR/nvm.sh" ]]; then
  12. # Load nvm if it exists in $NVM_DIR
  13. source "$NVM_DIR/nvm.sh" ${NVM_LAZY+"--no-use"}
  14. else
  15. # Otherwise try to load nvm installed via Homebrew
  16. # User can set this if they have an unusual Homebrew setup
  17. NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}"
  18. # Load nvm from Homebrew location if it exists
  19. [[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh" ${NVM_LAZY+"--no-use"}
  20. fi
  21. # Call nvm when first using node, npm or yarn
  22. if (( $+NVM_LAZY )); then
  23. function node npm yarn {
  24. unfunction node npm yarn
  25. nvm use default
  26. command "$0" "$@"
  27. }
  28. fi
  29. # Load nvm bash completion
  30. for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
  31. if [[ -f "$nvm_completion" ]]; then
  32. # Load bashcompinit
  33. autoload -U +X bashcompinit && bashcompinit
  34. # Bypass compinit call in nvm bash completion script. See:
  35. # https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
  36. ZSH_VERSION= source "$nvm_completion"
  37. break
  38. fi
  39. done
  40. unset NVM_HOMEBREW nvm_completion