Add brew support for nvm plugin inspired in rbenv plugin

This commit is contained in:
Diogo Azevedo 2015-06-05 12:35:36 -03:00
commit d6181dda51
2 changed files with 26 additions and 4 deletions

View file

@ -1,7 +1,7 @@
#compdef nvm
#autoload
[[ -s ~/.nvm/nvm.sh ]] || return 0
[[ -s $NVM_DIR/nvm.sh ]] || return 0
local -a _1st_arguments
_1st_arguments=(
@ -23,4 +23,4 @@ _arguments -C '*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "nvm subcommand" _1st_arguments
return
fi
fi

View file

@ -1,3 +1,25 @@
# The addition 'nvm install' attempts in ~/.profile
_homebrew-installed() {
type brew &> /dev/null
}
[[ -s ~/.nvm/nvm.sh ]] && . ~/.nvm/nvm.sh
_nvm-from-homebrew-installed() {
brew --prefix nvm &> /dev/null
}
FOUND_NVM=0
nvmdirs=("$HOME/.nvm" "/usr/local/nvm" "/opt/nvm" "/usr/local/opt/nvm")
if _homebrew-installed && _nvm-from-homebrew-installed ; then
nvmdirs=($(brew --prefix nvm) "${rbenvdirs[@]}")
fi
for nvmdir in "${nvmdirs[@]}" ; do
if [ -s $nvmdir/nvm.sh -a $FOUND_NVM -eq 0 ]; then
FOUND_NVM=1
if [[ $NVM_DIR = '' ]]; then
NVM_DIR=$nvmdir
fi
export NVM_DIR
source $nvmdir/nvm.sh
fi
done
unset nvmdir