Use .nvmrc file to to switch node version

This commit is contained in:
Mike Milkman 2016-04-21 21:40:19 +03:00
parent 6dbf497000
commit ac7e0a8dee

View File

@ -195,13 +195,13 @@ add-zsh-hook chpwd load-nvmrc
##### Automatic version switching for `.bashrc` with fallback to `nvm use default` ##### Automatic version switching for `.bashrc` with fallback to `nvm use default`
Put this into your `$HOME/.bashrc` to enable automatic version swithing whenever you enter a directory than contains an Put this into your `$HOME/.bashrc` to enable automatic version swithing whenever you enter a directory than contains an
`.node-version` file with a string telling nvm which node to `use`: `.nvmrc` file with a string telling nvm which node to `use`:
```bash ```bash
cd() { cd() {
builtin cd "$@" builtin cd "$@"
if [[ -f .node-version && -r .node-version ]]; then if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use "`cat .node-version`" nvm use
elif [[ `nvm current` != `nvm version default` ]]; then elif [[ `nvm current` != `nvm version default` ]]; then
nvm use default nvm use default
fi fi
@ -216,8 +216,8 @@ For example, on Ubuntu it should be placed into `$HOME/.bash_profile`:
```bash ```bash
cd() { cd() {
__zsh_like_cd cd "$@" __zsh_like_cd cd "$@"
if [[ -f .node-version && -r .node-version ]]; then if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use "`cat .node-version`" nvm use
elif [[ `nvm current` != `nvm version default` ]]; then elif [[ `nvm current` != `nvm version default` ]]; then
nvm use default nvm use default
fi fi