Skip to content

Commit

Permalink
run nvm use automatically in a directory with a .nvmrc file
Browse files Browse the repository at this point in the history
  • Loading branch information
kremalicious committed Sep 5, 2023
1 parent 5dee9e6 commit 826f97c
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions exports
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,35 @@ export CDPATH=$CDPATH:~/Code

# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -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

# Calling nvm use automatically in a directory with a .nvmrc file
# https://github.com/nvm-sh/nvm#zsh
autoload -U add-zsh-hook

load-nvmrc() {
local nvmrc_path
nvmrc_path="$(nvm_find_nvmrc)"

if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version
nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then
nvm use
fi
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}

add-zsh-hook chpwd load-nvmrc
load-nvmrc


# defer loading until needed for faster shell startup
#declare -a NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
Expand All @@ -51,7 +79,7 @@ export NVM_DIR="$HOME/.nvm"
#done

# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache

Expand Down

0 comments on commit 826f97c

Please sign in to comment.