From 913d20e1624cd79bb53ac978e2e3e12d63b1f56a Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Wed, 13 May 2020 17:05:27 +0000 Subject: [PATCH] Lazyload nvm when used --- .bashrc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.bashrc b/.bashrc index f06ce1c..6dbf4f0 100644 --- a/.bashrc +++ b/.bashrc @@ -37,3 +37,31 @@ bind '"jj":"\e"' export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -t -g ""' export FZF_COMPLETION_OPTS='-x' + +# nvm +lazy_load_nvm() { + unset -f nvm node npm npx + 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 +} + +nvm() { + lazy_load_nvm + nvm $@ +} + +node() { + lazy_load_nvm + node $@ +} + +npm() { + lazy_load_nvm + npm $@ +} + +npx() { + lazy_load_nvm + npx $@ +}