Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
78e85c7d
Unverified
Commit
78e85c7d
authored
Oct 06, 2022
by
Carlo
Committed by
GitHub
Oct 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(nvm): source nvm script only when used (#11205)
closes #11042
parent
570158e4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
25 deletions
+19
-25
README.md
plugins/nvm/README.md
+3
-3
nvm.plugin.zsh
plugins/nvm/nvm.plugin.zsh
+16
-22
No files found.
plugins/nvm/README.md
View file @
78e85c7d
...
@@ -22,9 +22,9 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced:
...
@@ -22,9 +22,9 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced:
nvm has been installed, regardless of chip architecture, use
`NVM_HOMEBREW=$(brew --prefix nvm)`
.
nvm has been installed, regardless of chip architecture, use
`NVM_HOMEBREW=$(brew --prefix nvm)`
.
-
**`NVM_LAZY`**
: if you want the plugin to defer the load of nvm to speed-up the start of your zsh session,
-
**`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
set
`NVM_LAZY`
to
`1`
. This will
source nvm script only when using it, and will create a function for
`node`
,
for
`node`
,
`
npm`
,
`yarn`
, and the command(s) specified by
`NVM_LAZY_CMD`
, so when you call either of them,
`npm`
,
`p
npm`
,
`yarn`
, and the command(s) specified by
`NVM_LAZY_CMD`
, so when you call either of them,
nvm will
load with
`nvm use default`
.
nvm will
be loaded and run with default version
.
-
**`NVM_LAZY_CMD`**
: if you want additional command(s) to trigger lazy loading of nvm, set
`NVM_LAZY_CMD`
to
-
**`NVM_LAZY_CMD`**
: if you want additional command(s) to trigger lazy loading of nvm, set
`NVM_LAZY_CMD`
to
the command or an array of the commands.
the command or an array of the commands.
...
...
plugins/nvm/nvm.plugin.zsh
View file @
78e85c7d
...
@@ -4,39 +4,33 @@ if [[ -z "$NVM_DIR" ]]; then
...
@@ -4,39 +4,33 @@ if [[ -z "$NVM_DIR" ]]; then
export
NVM_DIR
=
"
$HOME
/.nvm"
export
NVM_DIR
=
"
$HOME
/.nvm"
elif
[[
-d
"
${
XDG_CONFIG_HOME
:-
$HOME
/.config
}
/nvm"
]]
;
then
elif
[[
-d
"
${
XDG_CONFIG_HOME
:-
$HOME
/.config
}
/nvm"
]]
;
then
export
NVM_DIR
=
"
${
XDG_CONFIG_HOME
:-
$HOME
/.config
}
/nvm"
export
NVM_DIR
=
"
${
XDG_CONFIG_HOME
:-
$HOME
/.config
}
/nvm"
elif
((
$+
commands[brew]
))
;
then
NVM_HOMEBREW
=
"
${
NVM_HOMEBREW
:-${
HOMEBREW_PREFIX
:-$(
brew
--prefix
)}
/opt/nvm
}
"
if
[[
-d
"
$NVM_HOMEBREW
"
]]
;
then
export
NVM_DIR
=
"
$NVM_HOMEBREW
"
fi
fi
fi
fi
fi
# Don't try to load nvm if command already available
# Don't try to load nvm if command already available
# Note: nvm is a function so we need to use `which`
# Note: nvm is a function so we need to use `which`
!
which nvm &>/dev/null
||
return
which nvm &>/dev/null
&&
return
if
[[
-f
"
$NVM_DIR
/nvm.sh"
]]
;
then
if
((
$+
NVM_LAZY
))
;
then
# Call nvm when first using nvm, node, npm, pnpm, yarn or $NVM_LAZY_CMD
function
nvm node npm pnpm yarn
$NVM_LAZY_CMD
{
unfunction nvm node npm pnpm yarn
$NVM_LAZY_CMD
# Load nvm if it exists in $NVM_DIR
# Load nvm if it exists in $NVM_DIR
source
"
$NVM_DIR
/nvm.sh"
${
NVM_LAZY
+
"--no-use"
}
[[
-f
"
$NVM_DIR
/nvm.sh"
]]
&&
source
"
$NVM_DIR
/nvm.sh"
elif
((
$+
commands[brew]
))
;
then
"
$0
"
"
$@
"
# Otherwise try to load nvm installed via Homebrew
}
# User can set this if they have an unusual Homebrew setup
elif
[[
-f
"
$NVM_DIR
/nvm.sh"
]]
;
then
NVM_HOMEBREW
=
"
${
NVM_HOMEBREW
:-${
HOMEBREW_PREFIX
:-$(
brew
--prefix
)}
/opt/nvm
}
"
# Load nvm if it exists in $NVM_DIR
# Load nvm from Homebrew location if it exists
source
"
$NVM_DIR
/nvm.sh"
if
[[
-f
"
$NVM_HOMEBREW
/nvm.sh"
]]
;
then
source
"
$NVM_HOMEBREW
/nvm.sh"
${
NVM_LAZY
+
"--no-use"
}
else
return
fi
else
else
return
return
fi
fi
# Call nvm when first using node, npm or yarn
if
((
$+
NVM_LAZY
))
;
then
function
node npm yarn
$NVM_LAZY_CMD
{
unfunction node npm yarn
$NVM_LAZY_CMD
nvm use default
command
"
$0
"
"
$@
"
}
fi
# Autoload nvm when finding a .nvmrc file in the current directory
# Autoload nvm when finding a .nvmrc file in the current directory
# Adapted from: https://github.com/nvm-sh/nvm#zsh
# Adapted from: https://github.com/nvm-sh/nvm#zsh
if
((
$+
NVM_AUTOLOAD
))
;
then
if
((
$+
NVM_AUTOLOAD
))
;
then
...
...
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