nvm: simplify nvm.sh and bash completion loading
This commit is contained in:
parent
ef44416df2
commit
d8cb670235
|
@ -1,8 +1,6 @@
|
||||||
# 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}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,45 +1,30 @@
|
||||||
# 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
|
if [[ -f "$NVM_DIR/nvm.sh" ]]; then
|
||||||
# User-specified path
|
# Load nvm if it exists in $NVM_DIR
|
||||||
nvm_install_dir=$NVM_INSTALL_DIR
|
source "$NVM_DIR/nvm.sh"
|
||||||
else
|
else
|
||||||
# Well-known common installation locations for NVM
|
# Otherwise try to load nvm installed via Homebrew
|
||||||
install_locations=( ~/.nvm )
|
# User can set this if they have an unusual Homebrew setup
|
||||||
[[ -n $NVM_DIR ]] && install_locations=($NVM_DIR $install_locations)
|
NVM_HOMEBREW="${NVM_HOMEBREW:-/usr/local/opt/nvm}"
|
||||||
# Mac Homebrew sticks
|
# Load nvm from Homebrew location if it exists
|
||||||
which brew &>/dev/null && install_locations+=$(brew --prefix nvm)
|
[[ -f "$NVM_HOMEBREW/nvm.sh" ]] && source "$NVM_HOMEBREW/nvm.sh"
|
||||||
for dir ($install_locations); do
|
fi
|
||||||
if [[ -s $dir/nvm.sh ]]; then
|
|
||||||
nvm_install_dir=$dir
|
# 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
|
||||||
|
# Load bashcompinit
|
||||||
|
autoload -U +X bashcompinit && bashcompinit
|
||||||
|
# Bypass compinit call in nvm bash completion script. See:
|
||||||
|
# https://github.com/nvm-sh/nvm/blob/4436638/bash_completion#L86-L93
|
||||||
|
ZSH_VERSION= source "$nvm_completion"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -n $nvm_install_dir ]]; then
|
unset NVM_HOMEBREW nvm_completion
|
||||||
source $nvm_install_dir/nvm.sh
|
|
||||||
else
|
|
||||||
# No NVM installation found
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Locate and use the completion file shipped with NVM, instead of this
|
|
||||||
# plugin's completion
|
|
||||||
# (Their bash completion file has zsh portability support)
|
|
||||||
if [[ $ZSH_NVM_BUNDLED_COMPLETION == true ]]; then
|
|
||||||
local bash_comp_file
|
|
||||||
# Homebrew relocates the bash completion file, so look multiple places
|
|
||||||
for bash_comp_file ( bash_completion etc/bash_completion.d/nvm ); do
|
|
||||||
if [[ -s $nvm_install_dir/$bash_comp_file ]]; then
|
|
||||||
source $nvm_install_dir/$bash_comp_file
|
|
||||||
break;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue