Merge 202d8a50a4 into 217a5bb0de
This commit is contained in:
commit
f01fd23861
33
README.md
33
README.md
|
|
@ -20,8 +20,9 @@
|
||||||
- [Listing versions](#listing-versions)
|
- [Listing versions](#listing-versions)
|
||||||
- [.nvmrc](#nvmrc)
|
- [.nvmrc](#nvmrc)
|
||||||
- [Deeper Shell Integration](#deeper-shell-integration)
|
- [Deeper Shell Integration](#deeper-shell-integration)
|
||||||
- [zsh](#zsh)
|
|
||||||
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
|
||||||
|
- [zsh](#zsh)
|
||||||
|
- [other shells (e.g. bash)](#other-shells-eg-bash)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
- [Running tests](#running-tests)
|
- [Running tests](#running-tests)
|
||||||
- [Bash completion](#bash-completion)
|
- [Bash completion](#bash-completion)
|
||||||
|
|
@ -377,16 +378,11 @@ You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into you
|
||||||
|
|
||||||
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` development team. We are, however, accepting pull requests for more examples.
|
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` development team. We are, however, accepting pull requests for more examples.
|
||||||
|
|
||||||
#### zsh
|
#### Calling `nvm use` automatically in a directory with a `.nvmrc` file
|
||||||
|
|
||||||
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
|
This shell function will install (if needed) and `nvm use` the specified Node version when an `.nvmrc` is found, and `nvm use default` otherwise.
|
||||||
|
|
||||||
Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
|
```sh
|
||||||
`.nvmrc` file with a string telling nvm which node to `use`:
|
|
||||||
|
|
||||||
```zsh
|
|
||||||
# place this after nvm initialization!
|
|
||||||
autoload -U add-zsh-hook
|
|
||||||
load-nvmrc() {
|
load-nvmrc() {
|
||||||
local node_version="$(nvm version)"
|
local node_version="$(nvm version)"
|
||||||
local nvmrc_path="$(nvm_find_nvmrc)"
|
local nvmrc_path="$(nvm_find_nvmrc)"
|
||||||
|
|
@ -404,10 +400,29 @@ load-nvmrc() {
|
||||||
nvm use default
|
nvm use default
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`), add `load-nvmrc` along with one of the following hook listeners to call `load-nvmrc` whenever you enter a new directory:
|
||||||
|
|
||||||
|
##### zsh
|
||||||
|
|
||||||
|
```zsh
|
||||||
|
autoload -U add-zsh-hook
|
||||||
add-zsh-hook chpwd load-nvmrc
|
add-zsh-hook chpwd load-nvmrc
|
||||||
load-nvmrc
|
load-nvmrc
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### other shells (e.g. bash)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# note: overrides the `cd` command
|
||||||
|
cd() {
|
||||||
|
builtin cd "$1"
|
||||||
|
load-nvmrc
|
||||||
|
}
|
||||||
|
load-nvmrc
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
nvm is released under the MIT license.
|
nvm is released under the MIT license.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue