Skip to content

Instantly share code, notes, and snippets.

@tobiashm
Created August 18, 2017 09:35
Show Gist options
  • Save tobiashm/64092ca417361bfefa84046392803719 to your computer and use it in GitHub Desktop.
Save tobiashm/64092ca417361bfefa84046392803719 to your computer and use it in GitHub Desktop.
Change nvm version using RVM hooks (place in ~/.rvm/hooks/after_cd_nvm)
#!/usr/bin/env bash
# Requirements:
# brew install jq node
# nvm use system; npm -g install semver
if [ -f package.json ]; then
requested_node_version=$(jq -r '.engines.node' package.json)
if [ "$requested_node_version" != "" ]; then
node_version=$(nvm_ls | xargs env NODE_VERSION=system ~/.nvm/nvm-exec semver -r "$requested_node_version")
[ "$node_version" != "" ] && [ $(nvm current) != "v$node_version" ] && nvm use "$node_version"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment