[readme] include deeper integration instructions for fish

Jared Ramirez 2020-04-29 15:25:23 -07:00 committed by Jordan Harband
parent 8e1e5df059
commit dcc8059ef8
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
1 changed files with 41 additions and 0 deletions

View File

@ -31,6 +31,8 @@
- [Automatically call `nvm use`](#automatically-call-nvm-use) - [Automatically call `nvm use`](#automatically-call-nvm-use)
- [zsh](#zsh) - [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)
- [fish](#fish)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file-1)
- [License](#license) - [License](#license)
- [Running Tests](#running-tests) - [Running Tests](#running-tests)
- [Bash Completion](#bash-completion) - [Bash Completion](#bash-completion)
@ -536,6 +538,45 @@ add-zsh-hook chpwd load-nvmrc
load-nvmrc load-nvmrc
``` ```
#### fish
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
This requires that you have [bass](https://github.com/edc/bass) installed.
```fish
# ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
# ~/.config/fish/functions/nvm_find_nvmrc.fish
function nvm_find_nvmrc
bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc
end
# ~/.config/fish/functions/load_nvm.fish
function load_nvm --on-variable="PWD"
set -l default_node_version (nvm version default)
set -l node_version (nvm version)
set -l nvmrc_path (nvm_find_nvmrc)
if test -n "$nvmrc_path"
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
if test "$nvmrc_node_version" = "N/A"
nvm install $nvmrc_node_version
else if test nvmrc_node_version != node_version
nvm use $nvmrc_node_version
end
else if test "$node_version" != "$default_node_version"
echo "Reverting to default Node version"
nvm use default
end
end
# ~/.config/fish/config.fish
# You must call it on initialization or listening to directory switching won't work
load_nvm
```
## License ## License
nvm is released under the MIT license. nvm is released under the MIT license.