brew install fish
Set it as default macOS shell https://stackoverflow.com/questions/453236/how-to-set-my-default-shell-on-mac/20506404#20506404
https://github.com/oh-my-fish/oh-my-fish
curl -L https://get.oh-my.fish | fish
omf install nvm
This is based on original zsh function.
Put this into your ~/.config/fish/config.fish to call nvm use automatically whenever you
enter a directory that contains an .nvmrc file with a string telling nvm which node to use:
function __check_nvm --on-variable PWD --description 'Do nvm stuff'
set node_version (nvm version)
if test -f .nvmrc
set nvmrc_node_version (nvm version (cat .nvmrc))
if [ $nvmrc_node_version = "N/A" ]
nvm install
else if [ $nvmrc_node_version != $node_version ]
nvm use
end
else if [ $node_version != (nvm version default) ]
echo Reverting to nvm default version
nvm use default
end
end
# To check current dir upon Fish session start
__check_nvm
Upper function tend to be pretty slow since it's triggered on every cd. There is an alternavite version that only works if there is .nvmrc in current dir (oh my, much faster!):
function __check_nvm --on-variable PWD --description 'Do nvm stuff'
if test -f .nvmrc
set node_version (nvm version)
set nvmrc_node_version (nvm version (cat .nvmrc))
if [ $nvmrc_node_version = "N/A" ]
nvm install
else if [ $nvmrc_node_version != $node_version ]
nvm use
end
end
end
__check_nvm
https://github.com/creationix/nvm#installation
Latest editon that assumes the updated API of nvm utility:
function __check_nvm --on-variable PWD --description 'Do nvm stuff'
if test -f .nvmrc
set node_version (node -v)
set nvmrc_node_version (nvm list | grep (cat .nvmrc))
if set -q $nvmrc_node_version
nvm install
else if string match -q -- "*$node_version" $nvmrc_node_version
# already current node version
else
nvm use
end
end
end
We can still have the functionality without the performance hit: