Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- Only works for common aliases like `default`, `system`, `node`, `lts/*`, `iojs` etc. - Prevent unnecessary running of `nvm use`

authored by Daniel Li · committed by Jordan Harband · parent 2410215 · Browse files · 1 file+9 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+9 added−8 removed

  • other:+9 added−8 removed

1 file+9 added−8 removed

modified:README.md+9 added-8 removed
455 unmodified lines
456 elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then457 declare nvm_version458 nvm_version=$(<"$nvm_path"/.nvmrc)459460 # Add the `v` suffix if it does not exists in the .nvmrc file461 if [[ $nvm_version != v* ]]; then462 nvm_version="v""$nvm_version"463 fi460 declare locally_resolved_nvm_version461 # `nvm ls` will check all locally-available versions462 # If there are multiple matching versions, take the latest one463 # Remove the `->` and `*` characters and spaces464 # `locally_resolved_nvm_version` will be `N/A` if no local versions are found465 locally_resolved_nvm_version=$(nvm ls --no-colors $(<"./.nvmrc") | tail -1 | tr -d '\->*' | tr -d '[:space:]')466467 # If it is not already installed, install it466 if [[ $(nvm ls "$nvm_version" | tr -d '[:space:]') == "N/A" ]]; then468 # `nvm install` will implicitly use the newly-installed version469 if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then470 nvm install "$nvm_version";468 fi469470 if [[ $(nvm current) != "$nvm_version" ]]; then471 elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then472 nvm use "$nvm_version";473 fi474 fi475}
247 unmodified lines