Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Oh My Zsh
Commits
8c8fe2a1
Commit
8c8fe2a1
authored
Jan 13, 2017
by
Danny Grove
Committed by
Marc Cornellà
Oct 09, 2020
Browse files
nvm: add autoloading of nvm version in .nvmrc
Closes #5782 Fixes #8959 Closes #8976
parent
8163f650
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugins/nvm/README.md
View file @
8c8fe2a1
...
...
@@ -20,3 +20,7 @@ plugins=(... nvm)
-
**`NVM_LAZY`**
: if you want the plugin to defer the load of nvm to speed-up the start of your zsh session,
set
`NVM_LAZY`
to
`1`
. This will use the
`--no-use`
parameter when loading nvm, and will create a function
for
`node`
,
`npm`
and
`yarn`
, so when you call either of these three, nvm will load with
`nvm use default`
.
-
**`NVM_AUTOLOAD`**
: if
`NVM_AUTOLOAD`
is set to
`1`
, the plugin will automatically load a node version when
if finds a
[
`.nvmrc` file
](
https://github.com/nvm-sh/nvm#nvmrc
)
in the current working directory indicating
which node version to load.
plugins/nvm/nvm.plugin.zsh
View file @
8c8fe2a1
...
...
@@ -35,6 +35,33 @@ if (( $+NVM_LAZY )); then
}
fi
# Autoload nvm when finding a .nvmrc file in the current directory
# Adapted from: https://github.com/nvm-sh/nvm#zsh
if
((
$+
NVM_AUTOLOAD
))
;
then
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
}
autoload
-U
add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
fi
# Load nvm bash completion
for
nvm_completion
in
"
$NVM_DIR
/bash_completion"
"
$NVM_HOMEBREW
/etc/bash_completion.d/nvm"
;
do
if
[[
-f
"
$nvm_completion
"
]]
;
then
...
...
@@ -47,4 +74,4 @@ for nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_complet
fi
done
unset
NVM_HOMEBREW NVM_LAZY nvm_completion
unset
NVM_HOMEBREW NVM_LAZY
NVM_AUTOLOAD
nvm_completion
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment