Skip to content

Instantly share code, notes, and snippets.

@kendricktan
Created October 24, 2019 00:05
Show Gist options
  • Select an option

  • Save kendricktan/9d2ca146b69e93e3dc32d9ea7a232e0e to your computer and use it in GitHub Desktop.

Select an option

Save kendricktan/9d2ca146b69e93e3dc32d9ea7a232e0e to your computer and use it in GitHub Desktop.
Lazy load NVM
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