Last active
January 16, 2026 12:02
-
-
Save bertolo1988/83976149210402c224dfd66f8d11f8a1 to your computer and use it in GitHub Desktop.
Snippet of code for .zshrc config to run "nvm use" command if .nvmrc file is present in the 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
| # Automatically call nvm use on directory change | |
| # Only changes version if .nvmrc is found | |
| autoload -U add-zsh-hook | |
| load-nvmrc() { | |
| local nvmrc_path="$(nvm_find_nvmrc)" | |
| if [ -n "$nvmrc_path" ]; then | |
| local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") | |
| if [ "$nvmrc_node_version" = "N/A" ]; then | |
| nvm install | |
| elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then | |
| nvm use | |
| fi | |
| 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