Created
October 24, 2019 00:05
-
-
Save kendricktan/9d2ca146b69e93e3dc32d9ea7a232e0e to your computer and use it in GitHub Desktop.
Lazy load NVM
This file contains hidden or 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