Add comments to the zshrc hook reading .nvmrc

This commit is contained in:
Zack Light 2021-12-16 17:48:39 -08:00 committed by Zack Light
parent a26573a157
commit 67e9eef756

View File

@ -604,8 +604,7 @@ This alias would search 'up' from your current directory in order to detect a `.
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file ##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
Put this into your `$HOME/.zshrc` after nvm initialization to call `nvm use` automatically whenever you enter a directory that contains an Put this into your `$HOME/.zshrc` after nvm initialization to call `nvm use` automatically.
`.nvmrc` file with a string telling nvm which node to `use`:
Usage: follow the [simple official guide to create a .nvmrc file](https://github.com/nvm-sh/nvm#nvmrc) containing the node version number in the directory you want to use. Usage: follow the [simple official guide to create a .nvmrc file](https://github.com/nvm-sh/nvm#nvmrc) containing the node version number in the directory you want to use.
```zsh ```zsh
# place this after nvm initialization! # place this after nvm initialization!
@ -614,9 +613,11 @@ Put this into your `$HOME/.zshrc` after nvm initialization to call `nvm use` aut
local nvmrc_path=".nvmrc" local nvmrc_path=".nvmrc"
if [ -f "$nvmrc_path" ]; then if [ -f "$nvmrc_path" ]; then
# check if current node version is different from that in the config file
if [[ "$(which node)" != *"v$(cat "${nvmrc_path}")"* ]]; then if [[ "$(which node)" != *"v$(cat "${nvmrc_path}")"* ]]; then
nvm use --silent nvm use --silent
fi fi
# check if current node version is different from the default
elif [[ "$(which node)" != *"v$(cat ~/.nvm/alias/default)"* ]]; then elif [[ "$(which node)" != *"v$(cat ~/.nvm/alias/default)"* ]]; then
nvm use default --silent nvm use default --silent
fi fi