Skip to content

Instantly share code, notes, and snippets.

@mattriley
Last active March 14, 2020 01:26
Show Gist options
  • Save mattriley/5d963cb6735a888d9b51f3ba8c48f907 to your computer and use it in GitHub Desktop.
Save mattriley/5d963cb6735a888d9b51f3ba8c48f907 to your computer and use it in GitHub Desktop.
Writes a .nvmrc file containing the current Node LTS version. Requires nvm.
# Usage: ./nvmrc-latest-lts.sh
# Load NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Find latest Node LTS version
last_line=$(nvm ls-remote --lts --no-colors | tail -n 1)
# Match the version number
if [[ "$last_line" =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
old=$(cat .nvmrc 2>/dev/null)
new=${BASH_REMATCH[0]}
echo "Old: \"${old}\" New: \"${new}\""
echo $new > .nvmrc
else
echo "Failed to extract latest LTS version"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment