[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`
parent
2410215b6a
commit
ff77ac17af
17
README.md
17
README.md
|
@ -457,17 +457,18 @@ cdnvm(){
|
||||||
declare nvm_version
|
declare nvm_version
|
||||||
nvm_version=$(<"$nvm_path"/.nvmrc)
|
nvm_version=$(<"$nvm_path"/.nvmrc)
|
||||||
|
|
||||||
# Add the `v` suffix if it does not exists in the .nvmrc file
|
declare locally_resolved_nvm_version
|
||||||
if [[ $nvm_version != v* ]]; then
|
# `nvm ls` will check all locally-available versions
|
||||||
nvm_version="v""$nvm_version"
|
# If there are multiple matching versions, take the latest one
|
||||||
fi
|
# 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 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";
|
nvm install "$nvm_version";
|
||||||
fi
|
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
|
||||||
|
|
||||||
if [[ $(nvm current) != "$nvm_version" ]]; then
|
|
||||||
nvm use "$nvm_version";
|
nvm use "$nvm_version";
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue