Skip to content

Instantly share code, notes, and snippets.

@Flexicon
Created September 22, 2018 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Flexicon/553186aea385d04205af12a94876a0ba to your computer and use it in GitHub Desktop.
Save Flexicon/553186aea385d04205af12a94876a0ba to your computer and use it in GitHub Desktop.
Lazy load NVM (from reddit user sscotth)
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