Created
November 21, 2021 11:16
-
-
Save MunifTanjim/b517760c856b6de987a159719ff50f6d to your computer and use it in GitHub Desktop.
NVM Lazy Loading
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
export NVM_DIR="${HOME}/.local/share/nvm" | |
PATH="./node_modules/.bin:${PATH}" | |
if [ -d "${NVM_DIR}" ]; then | |
__node_global_bins=("nvm" "node" $(find ${NVM_DIR}/versions/node -maxdepth 3 -path '*/bin/*' -type l -print0 2>/dev/null | xargs -0 -n1 basename | sort | uniq)) | |
__init_nvm() { | |
unset -f ${__node_global_bins[@]} >/dev/null 2>&1 | |
unset __node_global_bins | |
unset -f __init_nvm | |
if [ -s "${NVM_DIR}/nvm.sh" ]; then | |
. "${NVM_DIR}/nvm.sh" | |
fi | |
} | |
for bin in "${__node_global_bins[@]}"; do | |
eval "${bin}(){ __init_nvm; ${bin} \$@; }" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment