How to get nvm
to run inside the fish
shell.
See the following for instructions:
fisher
is a package manager for fish
.
It can be installed using the following command:
curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
bass
is a way to run bash
scripts on fish
.
It can be installed using the following command:
fisher add edc/bass
Create a file at ~/.config/fish/functions/nvm.fish
containing:
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
replacing ~/.nvm/nvm.sh
with your installation directory if installed in a non-standard location or by a package manager.
nvm
is now working inside the fish
shell.
nvm
provides scripts to allow nvm
to have deeper integration into bash
or zsh
.
This is a port of the original zsh function by nvm
to fish
.
Put this into your ~/.config/fish/config.fish
to call nvm use
automatically whenever you
enter a directory that has contains, or has a parent directory that contains, an .nvmrc
file with a string telling nvm which version of node to use
:
function find_up
set path (pwd)
while test $path != "/"
and not test -e "$path/$argv[1]"
set path (dirname $path)
end
if test -e "$path/$argv[1]"
echo $path
else
echo ""
end
end
function __check_nvm --on-variable PWD
if status --is-command-substitution
return
end
set nvm_path (find_up ".nvmrc" | tr -d '[:space:]')
if test "$nvm_path" != ""
set nvmrc_node_version (nvm version (cat "$nvm_path/.nvmrc") '; 2>1')
if test "$nvmrc_node_version" = "N/A"
echo "Installing node version "(cat "$nvm_path/.nvmrc")
nvm install
set nvm_node_version (nvm version)
else if test "$nvmrc_node_version" != (nvm version)
echo "Changing node version to $nvmrc_node_version"
nvm use
set nvm_node_version (nvm version)
end
echo "$nvm_path/.nvmrc"
else if test (nvm version) = "none"
nvm use default --silent
else if test (nvm version) != (nvm version default)
echo "Reverting node version to default"
nvm use default
end
end
__check_nvm
Thanks for this, works like a charm 👌! Just a quick note...
When
if test "$nvmrc_node_version" = "N/A"
istrue
, the next line will echo"Installing node version N/A"
. I didn't thoroughly test this, but I believe that can be alleviated by: