Skip to content

Instantly share code, notes, and snippets.

@rodush
Last active March 30, 2023 07:18
Show Gist options
  • Select an option

  • Save rodush/30e6c53d464965c7d890e28bb289d12f to your computer and use it in GitHub Desktop.

Select an option

Save rodush/30e6c53d464965c7d890e28bb289d12f to your computer and use it in GitHub Desktop.
Code snippet to enable switching of the node js environment based on configuration from the `.nvmrc` file
# Put this somewhere in the ~/.zshrc file
load-nvmrc() {
local nvmrc_path="$(pwd -P)/.nvmrc"
if [[ -a "$nvmrc_path" ]]; then
local nvmrc_node_version=$(cat "${nvmrc_path}")
if [ "$nvmrc_node_version" = "N/A" ]; then
n latest
elif [ "$nvmrc_node_version" != "$current_node_version" ]; then
n $nvmrc_node_version
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