Last active
March 30, 2023 07:18
-
-
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
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
| # 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