nvm.plugin.zsh 1.5 KB

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