From 3f8696e0770e8c35dbdd61b4fd56a75296d155ad Mon Sep 17 00:00:00 2001 From: Ryo Shen Date: Wed, 13 Sep 2023 15:18:03 +0800 Subject: [PATCH] auto switch node version --- home/.aliasrc | 21 --------------------- home/.zshrc | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/home/.aliasrc b/home/.aliasrc index 7a76b1d..7f83ba5 100644 --- a/home/.aliasrc +++ b/home/.aliasrc @@ -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 diff --git a/home/.zshrc b/home/.zshrc index d00ca29..f3149b5 100644 --- a/home/.zshrc +++ b/home/.zshrc @@ -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"