Created
December 19, 2024 02:31
-
-
Save Drumstix42/15759e798ff2a26c70acda0328358a0c to your computer and use it in GitHub Desktop.
Load nvm version based on nvmrc for Windows
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
| # ------------------------------------------------------ | |
| # Load proper nvm version if a nvmrc is given on WINDOWS | |
| # ------------------------------------------------------ | |
| load-nvmrc() { | |
| if [[ -f .nvmrc && -r .nvmrc ]]; then | |
| declare version; | |
| version="$(< .nvmrc)"; | |
| if [ -z "$(node -v | grep $version)" ]; then | |
| if [ -z "$(nvm list | grep $version)" ]; then | |
| echo "Node $version is not currently installed through nvm. Installing."; | |
| nvm install $version; | |
| fi | |
| nvm use $version; | |
| else | |
| return; # same version we're running, no need for anything else. | |
| fi | |
| fi | |
| } | |
| load-nvmrc | |
| # Override `cd` to auto-load correct version of Node on enterting directory. | |
| cd() { builtin cd "$@"; 'load-nvmrc'; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment