From 9440d09f78403c69489047e9f7b1dfe2ceb00b0d Mon Sep 17 00:00:00 2001 From: Marco D'Agostini Date: Sun, 20 Dec 2020 22:22:04 -0500 Subject: [PATCH] ubuntu: fix: nvm lazy-loading script --- ubuntu fresh install.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ubuntu fresh install.md b/ubuntu fresh install.md index 1555312..cb5f2e5 100644 --- a/ubuntu fresh install.md +++ b/ubuntu fresh install.md @@ -131,15 +131,18 @@ function mkcd () { mkdir -p "$@" && cd "$@"; } ```bash export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && . $NVM_DIR/nvm.sh --no-use; # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && . $NVM_DIR/bash_completion; # This loads nvm bash_completion -__nvm_load_node () { +[ -s "$NVM_DIR/nvm.sh" ] && . $NVM_DIR/nvm.sh --no-use; +[ -s "$NVM_DIR/bash_completion" ] && . $NVM_DIR/bash_completion; +function __nvm_load_node () { unalias node npm npx; nvm use 2> /dev/null || nvm use default; + command=$1; + shift 1; + $command $@; } -alias node='__nvm_load_node; node $@' -alias npm='__nvm_load_node; npm $@' -alias npx='__nvm_load_node; npx $@' +alias node='__nvm_load_node node $@' +alias npm='__nvm_load_node npm $@' +alias npx='__nvm_load_node npx $@' ``` #### Enable most