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
Ohmyzsh
Commits
d8cb6702
Commit
d8cb6702
authored
Oct 09, 2020
by
Marc Cornellà
Browse files
nvm: simplify nvm.sh and bash completion loading
parent
ef44416d
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/nvm.zsh
View file @
d8cb6702
# get the nvm-controlled node.js version
# get the nvm-controlled node.js version
function
nvm_prompt_info
()
{
function
nvm_prompt_info
()
{
local
nvm_prompt
which nvm &>/dev/null
||
return
which nvm &>/dev/null
||
return
nvm_prompt
=
$(
nvm current
)
local
nvm_prompt
=
${
$(
nvm current
)
#v
}
nvm_prompt
=
${
nvm_prompt
#v
}
echo
"
${
ZSH_THEME_NVM_PROMPT_PREFIX
}${
nvm_prompt
}${
ZSH_THEME_NVM_PROMPT_SUFFIX
}
"
echo
"
${
ZSH_THEME_NVM_PROMPT_PREFIX
}${
nvm_prompt
}${
ZSH_THEME_NVM_PROMPT_SUFFIX
}
"
}
}
plugins/nvm/nvm.plugin.zsh
View file @
d8cb6702
# nvm
# Set NVM_DIR if it isn't already defined
#
[[
-z
"
$NVM_DIR
"
]]
&&
export
NVM_DIR
=
"
$HOME
/.nvm"
# This plugin locates and loads nvm, looking for it in well-known locations.
()
{
# Don't try to load nvm if command already available
emulate
-L
zsh
which nvm &> /dev/null
&&
return
local
nvm_install_dir
=
""
dir
install_locations
if
[[
-n
$NVM_INSTALL_DIR
]]
;
then
# User-specified path
nvm_install_dir
=
$NVM_INSTALL_DIR
else
# Well-known common installation locations for NVM
install_locations
=(
~/.nvm
)
[[
-n
$NVM_DIR
]]
&&
install_locations
=(
$NVM_DIR
$install_locations
)
# Mac Homebrew sticks
which brew &>/dev/null
&&
install_locations+
=
$(
brew
--prefix
nvm
)
for
dir
(
$install_locations
)
;
do
if
[[
-s
$dir
/nvm.sh
]]
;
then
nvm_install_dir
=
$dir
break
fi
done
fi
if
[[
-n
$nvm_install_dir
]]
;
then
if
[[
-f
"
$NVM_DIR
/nvm.sh"
]]
;
then
source
$nvm_install_dir
/nvm.sh
# Load nvm if it exists in $NVM_DIR
else
source
"
$NVM_DIR
/nvm.sh"
# No NVM installation found
else
return
0
# Otherwise try to load nvm installed via Homebrew
fi
# User can set this if they have an unusual Homebrew setup
NVM_HOMEBREW
=
"
${
NVM_HOMEBREW
:-
/usr/local/opt/nvm
}
"
# Load nvm from Homebrew location if it exists
[[
-f
"
$NVM_HOMEBREW
/nvm.sh"
]]
&&
source
"
$NVM_HOMEBREW
/nvm.sh"
fi
# Locate and use the completion file shipped with NVM, instead of this
# Load nvm bash completion
# plugin's completion
for
nvm_completion
in
"
$NVM_DIR
/bash_completion"
"
$NVM_HOMEBREW
/etc/bash_completion.d/nvm"
;
do
# (Their bash completion file has zsh portability support)
if
[[
-f
"
$nvm_completion
"
]]
;
then
if
[[
$ZSH_NVM_BUNDLED_COMPLETION
==
true
]]
;
then
# Load bashcompinit
local
bash_comp_file
autoload
-U
+X bashcompinit
&&
bashcompinit
# Homebrew relocates the bash completion file, so look multiple places
# Bypass compinit call in nvm bash completion script. See:
for
bash_comp_file
(
bash_completion etc/bash_completion.d/nvm
)
;
do
# https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
if
[[
-s
$nvm_install_dir
/
$bash_comp_file
]]
;
then
ZSH_VERSION
=
source
"
$nvm_completion
"
source
$nvm_install_dir
/
$bash_comp_file
break
break
;
fi
done
fi
fi
}
done
unset
NVM_HOMEBREW 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