Skip to content

Instantly share code, notes, and snippets.

@cleaver
Created December 7, 2022 17:05
Show Gist options
  • Save cleaver/28a20373161e3bc8bfa9a903c3fab32f to your computer and use it in GitHub Desktop.
Save cleaver/28a20373161e3bc8bfa9a903c3fab32f to your computer and use it in GitHub Desktop.
Defer initializing nvm - speed up terminal login for zsh
# adapted from: https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(whence -w __init_nvm)" = "__init_nvm: function" ]; then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
declare -a __node_commands=('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack')
function __init_nvm() {
for i in "${__node_commands[@]}"; do unalias $i; done
. "$NVM_DIR"/nvm.sh
unset __node_commands
unset -f __init_nvm
}
for i in "${__node_commands[@]}"; do alias $i='__init_nvm && '$i; done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment