Last active
September 21, 2019 15:59
-
-
Save sillyslux/03ee400b8ef18ea8e5dfdf6ca364f43a to your computer and use it in GitHub Desktop.
delaying nvm load until first usage in session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
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 | |
----- | |
$ time source ./nvm_loader1.sh | |
real 0m0.889s | |
user 0m0.668s | |
sys 0m0.317s | |
$ time nvm --version | |
0.33.8 | |
real 0m0.007s | |
user 0m0.005s | |
sys 0m0.003s | |
$ time nvm --version | |
0.33.8 | |
real 0m0.009s | |
user 0m0.010s | |
sys 0m0.000s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export NVM_DIR="$HOME/.nvm" | |
loadnvm() { | |
unset -f npm npx node | |
[ -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() { loadnvm nvm $@; } | |
npm() { loadnvm npm $@; } | |
npx() { loadnvm npx $@; } | |
node() { loadnvm node $@; } | |
----- | |
$ time source ./nvm_loader2.sh | |
real 0m0.004s | |
user 0m0.004s | |
sys 0m0.000s | |
$ time nvm --version | |
0.33.8 | |
real 0m0.866s | |
user 0m0.643s | |
sys 0m0.283s | |
$ time nvm --version | |
0.33.8 | |
real 0m0.008s | |
user 0m0.007s | |
sys 0m0.003s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment