From bb29ba1359042994b230960635da91b2080afb73 Mon Sep 17 00:00:00 2001 From: ZhenHappy Date: Sat, 4 Feb 2017 16:10:11 +0800 Subject: [PATCH] Update nvm.plugin.zsh --- plugins/nvm/nvm.plugin.zsh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/nvm/nvm.plugin.zsh b/plugins/nvm/nvm.plugin.zsh index 86338aa7..c0073f02 100644 --- a/plugins/nvm/nvm.plugin.zsh +++ b/plugins/nvm/nvm.plugin.zsh @@ -1,6 +1,21 @@ +# if homebrew installed +_homebrew-installed() { + type brew &> /dev/null +} + +# if nvm from homebrew installed +_nvm-from-homebrew-installed() { + brew --prefix nvm &> /dev/null +} + # Set NVM_DIR if it isn't already defined [[ -z "$NVM_DIR" ]] && export NVM_DIR="$HOME/.nvm" # Load nvm if it exists -[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" -[[ -f "$(brew --prefix nvm)/nvm.sh" ]] && source "$(brew --prefix nvm)/nvm.sh" +if [[ -f "$NVM_DIR/nvm.sh" ]] ; then + source "$NVM_DIR/nvm.sh" +elif _homebrew-installed && _nvm-from-homebrew-installed ; then + source "$(brew --prefix nvm)/nvm.sh" +else + unset NVM_DIR +fi