Skip to content

Instantly share code, notes, and snippets.

@bertolo1988
Last active January 16, 2026 12:02
Show Gist options
  • Select an option

  • Save bertolo1988/83976149210402c224dfd66f8d11f8a1 to your computer and use it in GitHub Desktop.

Select an option

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
# 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