fix(nvm): fix slow terminal initialization
icyphox icyph0x@protonmail.com
Sat, 24 Feb 2018 17:09:02 +0530
1 files changed,
18 insertions(+),
3 deletions(-)
jump to
M
zsh/.zshrc
→
zsh/.zshrc
@@ -51,6 +51,21 @@ eval $(gnome-keyring-daemon --start)
export SSH_AUTH_SOCK fi -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +#export NVM_DIR="$HOME/.nvm" +#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +#[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +# Defer initialization of nvm until nvm, node or a node-dependent command is +# run. Ensure this block is only run once if .bashrc gets sourced multiple times +# by checking whether __init_nvm is a function. +if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(type __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