Skip to content

Instantly share code, notes, and snippets.

@sergeykuzmich
Created March 26, 2018 13:56
Show Gist options
  • Save sergeykuzmich/444fbdfa7b2e5800e20769159ed3cb61 to your computer and use it in GitHub Desktop.
Save sergeykuzmich/444fbdfa7b2e5800e20769159ed3cb61 to your computer and use it in GitHub Desktop.
# BEGIN UGLY HACK
# This lets us initialize nvm, node and any other global node binaries on demand (lazily)
# to save on shell startup time
export NVM_DIR="$HOME/.nvm"
declare -a NODE_GLOBALS=(`find $NVM_DIR/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
NODE_GLOBALS+=("node")
NODE_GLOBALS+=("nvm")
# Bootstrap nvm on demand
load_nvm() {
source "/usr/local/opt/nvm/nvm.sh"
# (Optional) Set the version of node to use from ~/.nvmrc if available
nvm use 2> /dev/null 1>&2 || true
# Do not reload nvm again
export NVM_LOADED=1
}
for node_cmd in "${NODE_GLOBALS[@]}"; do
eval "${node_cmd}() { unset -f ${node_cmd}; [ -z \${NVM_LOADED+x} ] && load_nvm; ${node_cmd} \$@; }"
done
# END UGLY HACK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment