Created
September 22, 2018 15:42
-
-
Save Flexicon/553186aea385d04205af12a94876a0ba to your computer and use it in GitHub Desktop.
Lazy load NVM (from reddit user sscotth)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -a NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`) | |
NODE_GLOBALS+=("node") | |
NODE_GLOBALS+=("nvm") | |
load_nvm () { | |
export NVM_DIR=~/.nvm | |
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" | |
} | |
for cmd in "${NODE_GLOBALS[@]}"; do | |
eval "${cmd}(){ unset -f ${NODE_GLOBALS}; load_nvm; ${cmd} \$@ }" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment