Created
November 15, 2024 16:01
-
-
Save vjo/682ffa1058d883a7a6e29f9e53b38ae5 to your computer and use it in GitHub Desktop.
Automate `nvm use` when changing directory
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
## | |
# Add the following to your `~/.zshrc` after nvm is initialized | |
## | |
# switch to the right node version automatically | |
function chpwd() { | |
# Executed whenever the current working directory is changed | |
if [[ -f .nvmrc && -r .nvmrc ]]; then | |
nvm use | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternative: https://johnlindquist.com/automatically-switch-node-versions-based-on-your-packagejson-and-precmd-in-zsh/