nvm.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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" --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" --no-use
  20. fi
  21. # Call nvm when first using node, npm or yarn
  22. function node npm yarn {
  23. unfunction node npm yarn
  24. nvm use default
  25. command "$0" "$@"
  26. }
  27. # Load nvm bash completion
  28. for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
  29. if [[ -f "$nvm_completion" ]]; then
  30. # Load bashcompinit
  31. autoload -U +X bashcompinit && bashcompinit
  32. # Bypass compinit call in nvm bash completion script. See:
  33. # https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
  34. ZSH_VERSION= source "$nvm_completion"
  35. break
  36. fi
  37. done
  38. unset NVM_HOMEBREW nvm_completion