Skip to content

Commit

Permalink
auto switch node version
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshen committed Sep 13, 2023
1 parent 3b8d76c commit 3f8696e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
21 changes: 0 additions & 21 deletions home/.aliasrc
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,3 @@ function tmc() {
function tml() {
tmutil listlocalsnapshots /System/Volumes/Data|awk -F. '{print $4}'
}

autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"

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

if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
22 changes: 22 additions & 0 deletions home/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ if [[ -f ~/.pathrc.local ]]; then
source ~/.pathrc.local
fi

# auto switch node version
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"

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

if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

# goenv
# git clone https://github.com/go-nv/goenv.git ~/.goenv
export GOENV_ROOT="$HOME/.goenv"
Expand Down

0 comments on commit 3f8696e

Please sign in to comment.