[New] add lts/-1 etc, to point to an LTS line relative to "latest"

This commit is contained in:
Jordan Harband
2020-03-04 01:03:36 -08:00
parent c372ff03e0
commit 4626d1aae6
4 changed files with 62 additions and 1 deletions

19
nvm.sh
View File

@@ -855,8 +855,25 @@ nvm_alias() {
return 1
fi
local NVM_ALIAS_DIR
NVM_ALIAS_DIR="$(nvm_alias_path)"
if [ "$(expr "${ALIAS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then
local N
N="$(echo "${ALIAS}" | cut -d '-' -f 2)"
local RESULT
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
if [ "${RESULT}" != '*' ]; then
nvm_alias "lts/${RESULT}"
return $?
else
nvm_err 'That many LTS releases do not exist yet.'
return 2
fi
fi
local NVM_ALIAS_PATH
NVM_ALIAS_PATH="$(nvm_alias_path)/${ALIAS}"
NVM_ALIAS_PATH="${NVM_ALIAS_DIR}/${ALIAS}"
if [ ! -f "${NVM_ALIAS_PATH}" ]; then
nvm_err 'Alias does not exist.'
return 2