Skip to content

Instantly share code, notes, and snippets.

@chfour
Created April 14, 2021 18:11
Show Gist options
  • Save chfour/db6573a2cfa5c6c80f5e42e201576725 to your computer and use it in GitHub Desktop.
Save chfour/db6573a2cfa5c6c80f5e42e201576725 to your computer and use it in GitHub Desktop.
nvmisslow.sh: A shell script that only loads nvm when it's needed
#!/bin/bash
# nvmisslow.sh: loads nvm only when needed
# because nvm is slow
# source from or paste into your shell's .rc
# this is a list of commands that will trigger __initnvm.
# if you have globally installed node modules, add them here
declare -a __node_cmds=('nvm' 'node' 'npm')
__initnvm(){
for i in "${__node_cmds[@]}"; do; unalias $i; done
source /usr/share/nvm/init-nvm.sh # you may need to change this, but idk, that's where it was on my machine
unset __node_cmds; unset -f __initnvm
}
for i in "${__node_cmds[@]}"; do; alias $i="__initnvm;$i"; done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment