Skip to content

Commit

Permalink
Shell hook instructions made more organized/specific.
Browse files Browse the repository at this point in the history
  • Loading branch information
benwiley4000 committed Jun 30, 2017
1 parent 1e2643a commit 202d8a5
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
- [Listing versions](#listing-versions)
- [.nvmrc](#nvmrc)
- [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)
- [Running tests](#running-tests)
- [Bash completion](#bash-completion)
Expand Down Expand Up @@ -343,14 +344,9 @@ If you prefer a lighter-weight solution, the recipes below have been contributed

#### Calling `nvm use` automatically in a directory with a `.nvmrc` file

##### zsh

Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
`.nvmrc` file with a string telling nvm which node to `use`:
This shell function will install (if needed) and `nvm use` the specified Node version when an `.nvmrc` is found, and `nvm use default` otherwise.

```zsh
# place this after nvm initialization!
autoload -U add-zsh-hook
```sh
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
Expand All @@ -368,25 +364,27 @@ load-nvmrc() {
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
```

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

Put this into `$HOME/.bashrc` (or `$HOME/.bash_profile`, or whatever you use) to override the `cd` command to mimic the above zsh-hook:
##### zsh

```bash
# place this after nvm initialization!
load-nvmrc() {
# same definition as zsh-hook
}
```zsh
autoload -U add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
```

##### other shells (e.g. bash)

```sh
# note: overrides the `cd` command
cd() {
builtin cd "$1"
load-nvmrc
}
load-nvmrc
```

## License
Expand Down

0 comments on commit 202d8a5

Please sign in to comment.