Created
October 12, 2020 16:42
-
-
Save dtom90/37cdf9278c2bc5467d904a47f0a91c74 to your computer and use it in GitHub Desktop.
Set nvm version based on package.json /engines/node when changing directories
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
| # NVM Initialization... | |
| # place this after nvm initialization! | |
| autoload -U add-zsh-hook | |
| load-nvmrc() { | |
| package_node_version="$(node -p "require('./package.json').engines.node")" >/dev/null 2>&1 | |
| if [ -n "$package_node_version" ]; then | |
| echo "Detected node version $package_node_version in package.json" | |
| nvm use $package_node_version | |
| fi | |
| } | |
| add-zsh-hook chpwd load-nvmrc | |
| load-nvmrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment