Created
May 31, 2024 19:05
-
-
Save fabiospampinato/5eee086397389ce69b737bf9232eb37f to your computer and use it in GitHub Desktop.
Code for avoiding calling NVM, which slows down the shell by a lot
This file contains 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/.nvm" | |
export NVM_DEFAULT_VERSION=$(cat $NVM_DIR/alias/default) | |
export PATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/bin:$PATH" | |
export MANPATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/share/man:$MANPATH" | |
export NODE_PATH="$NVM_DIR/versions/node/$NVM_DEFAULT_VERSION/lib/node_modules" | |
function find-up () { | |
local look=${PWD%/} | |
while [[ -n $look ]]; do | |
[[ -e $look/$1 ]] && { | |
printf '%s\n' "$look" | |
return 0 | |
} | |
look=${look%/*} | |
done | |
[[ -e /$1 ]] && { | |
echo / | |
return 0 | |
} | |
return 1 | |
} | |
function nvm () { | |
. "$NVM_DIR/nvm.sh" --no-use | |
nvm $@ | |
} | |
function load-nvmrc () { | |
local nvmrc_path="$(find-up .nvmrc)" | |
if [ -n "$nvmrc_path" ]; then | |
local current_version="$(node --version)" | |
local nvmrc_version="$(cat $nvmrc_path/.nvmrc)" | |
if [ "$nvmrc_version" != "$current_version" ]; then | |
nvm use $nvmrc_version | |
fi | |
fi | |
} | |
add-zsh-hook chpwd load-nvmrc | |
load-nvmrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment