Skip to content

Instantly share code, notes, and snippets.

@YSaxon
Last active August 19, 2024 18:48
Show Gist options
  • Save YSaxon/a1c97490794e8d1f668715cefb04808e to your computer and use it in GitHub Desktop.
Save YSaxon/a1c97490794e8d1f668715cefb04808e to your computer and use it in GitHub Desktop.
Lazy load homebrew node to speed up shell init time
# Add this to your zshrc etc
# modified from #http://broken-by.me/lazy-load-nvm/
setup_nvm(){
unset -f nvm node npm
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
}
nvm() {
setup_nvm
nvm "$@"
}
node() {
setup_nvm
node "$@"
}
npm() {
setup_nvm
npm "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment