Last active
May 26, 2016 20:31
-
-
Save mfdj/3370404ccb6a4a44701e62d6ea0d715d to your computer and use it in GitHub Desktop.
Extends n (https://github.com/tj/n) to pick node version from .node-version or package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n() { | |
# forward straght to n | |
[[ $# > 0 ]] && { | |
command n "$@" | |
return | |
} | |
# look for a version | |
[[ -f .node-version ]] && { | |
command n $(cat .node-version) && node --version | |
return | |
} | |
[[ -f package.json ]] && { | |
if command -v jq > /dev/null; then | |
command n $(jq -r .engines.node package.json | awk '{print $2}') && node --version | |
return | |
else | |
echo "could not parse package.json, missing jq — please 'brew install jq'" | |
fi | |
} | |
# use interactive picker | |
command n | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment