nvm: split out $NVM_DIR and $NVM_INSTALL_DIR

This commit is contained in:
Andrew Janke 2015-09-10 05:55:43 -04:00 committed by janke
commit 7f4707874f
3 changed files with 18 additions and 11 deletions

View file

@ -1,6 +1,5 @@
# get the nvm-controlled node.js version
function nvm_prompt_info() {
[[ -f "$NVM_DIR/nvm.sh" ]] || return
local nvm_prompt
which nvm &>/dev/null || return
nvm_prompt=$(nvm current)

View file

@ -6,7 +6,8 @@ The `nvm` plugin locates and loads [NVM](https://github.com/creationix/nvm) if i
This plugin looks in a few well-known locations for the NVM installation, in the following order:
* `$NVM_DIR` - Lets user force loading from an arbitrary location
* `$NVM_INSTALL_DIR` - Forces loading from an arbitrary location that may be different from the `$NVM_DIR` data directory. If provided, no other locations will be checked.
* `$NVM_DIR` - Arbitrary installation location that is also the data directory
* `~/.nvm` - Default installation location for NVM
* `$(brew --prefix nvm)` - Mac Homebrew's NVM installation location
@ -28,4 +29,6 @@ To use NVM's bundled bash completions, set `ZSH_NVM_BUNDLED_COMPLETION=true` in
### Environment Variables
* `$ZSH_NVM_BUNDLED_COMPLETION` - if `true`, uses NVM's own completion definition instead of the OMZ nvm plugin's definition.
* `$ZSH_NVM_BUNDLED_COMPLETION` - if `true`, uses NVM's own completion definition instead of the OMZ nvm plugin's definition
* `$NVM_INSTALL_DIR` - overrides installation search path
* `$NVM_DIR` - NVM data directory and possible installation location

View file

@ -4,24 +4,29 @@
() {
emulate -L zsh
local nvm_dir="" dir install_locations
if [[ -n $NVM_DIR ]]; then
nvm_dir=$NVM_DIR
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_dir=$dir
nvm_install_dir=$dir
break
fi
done
fi
if [[ -n $nvm_dir ]]; then
source $nvm_dir/nvm.sh
if [[ -n $nvm_install_dir ]]; then
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
@ -31,8 +36,8 @@
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_DIR/$bash_comp_file ]]; then
source $NVM_DIR/$bash_comp_file
if [[ -s $nvm_install_dir/$bash_comp_file ]]; then
source $nvm_install_dir/$bash_comp_file
break;
fi
done