Skip to content

Commit d1a22a6

Browse files
dijonkitchenljharb
authored andcommitted
[readme] cdnvm function: fix shellcheck errors
Resolves #3081
1 parent 0d9b5c2 commit d1a22a6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,9 @@ cdnvm() {
599599
fi
600600
fi
601601
}
602+
602603
alias cd='cdnvm'
603-
cd "$PWD"
604+
cdnvm "$PWD" || exit
604605
```
605606
606607
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
@@ -615,11 +616,14 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
615616
```zsh
616617
# place this after nvm initialization!
617618
autoload -U add-zsh-hook
619+
618620
load-nvmrc() {
619-
local nvmrc_path="$(nvm_find_nvmrc)"
621+
local nvmrc_path
622+
nvmrc_path="$(nvm_find_nvmrc)"
620623
621624
if [ -n "$nvmrc_path" ]; then
622-
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
625+
local nvmrc_node_version
626+
nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
623627
624628
if [ "$nvmrc_node_version" = "N/A" ]; then
625629
nvm install
@@ -631,6 +635,7 @@ load-nvmrc() {
631635
nvm use default
632636
fi
633637
}
638+
634639
add-zsh-hook chpwd load-nvmrc
635640
load-nvmrc
636641
```

0 commit comments

Comments
 (0)