Skip to content
Permalink
Browse files

[Docs] update `bash` `cdnvm` script to properly handle aliases

 - Only works for common aliases like `default`, `system`, `node`, `lts/*`, `iojs` etc.
 - Prevent unnecessary running of `nvm use`
  • Loading branch information...
d4nyll authored and ljharb committed Mar 12, 2019
1 parent 2410215 commit ff77ac17af8b45bbb76edaebbdc58827c693b7e2
Showing with 9 additions and 8 deletions.
  1. +9 −8 README.md
@@ -457,17 +457,18 @@ cdnvm(){
declare nvm_version
nvm_version=$(<"$nvm_path"/.nvmrc)
# Add the `v` suffix if it does not exists in the .nvmrc file
if [[ $nvm_version != v* ]]; then
nvm_version="v""$nvm_version"
fi
declare locally_resolved_nvm_version
# `nvm ls` will check all locally-available versions
# If there are multiple matching versions, take the latest one
# Remove the `->` and `*` characters and spaces
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
locally_resolved_nvm_version=$(nvm ls --no-colors $(<"./.nvmrc") | tail -1 | tr -d '\->*' | tr -d '[:space:]')
# If it is not already installed, install it
if [[ $(nvm ls "$nvm_version" | tr -d '[:space:]') == "N/A" ]]; then
# `nvm install` will implicitly use the newly-installed version
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
nvm install "$nvm_version";
fi
if [[ $(nvm current) != "$nvm_version" ]]; then
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
nvm use "$nvm_version";
fi
fi

0 comments on commit ff77ac1

Please sign in to comment.
You can’t perform that action at this time.