mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-07-03 14:13:43 +00:00
Introduce nvm function for fish
This is a wrapper around nvm. It's main function is to check and promote environment variables changes from nvm to fish. A little more is done to setup the environment in case that hasn't been done yet: * install a stable node version if it doesn't exist * set the default to stable alias if that hasn't been done yet Due to those actions, the first execution of `nvm` might take some time.
This commit is contained in:
parent
18b28e47a1
commit
1eac915fba
24
nvm.fish
Normal file
24
nvm.fish
Normal file
@ -0,0 +1,24 @@
|
||||
function nvm --description "Node version manager" -a nvm_command nvm_command_arg1
|
||||
set nvm_dir ~/.nvm
|
||||
set nvm_ $nvm_dir/nvm
|
||||
|
||||
# This sets some environment vars that we need to set too
|
||||
if test "$nvm_command" = "use"
|
||||
eval $nvm_ use --print-paths $nvm_command_arg1 | sed -re "s|^(\w+=)|set -x \1|g" -e "s|[=:]| |g" | grep "set -x" | .
|
||||
else
|
||||
# Make sure we can use node
|
||||
if test ! (which node)
|
||||
# Have we installed node at all ?
|
||||
if eval $nvm_ ls | grep "N/A" > /dev/null
|
||||
echo "No node installation found, installing stable"
|
||||
eval $nvm_ install stable
|
||||
end
|
||||
# Make sure we have a default picked
|
||||
if eval $nvm_ ls default | grep "N/A"
|
||||
eval $nvm_ alias default stable
|
||||
end
|
||||
nvm use default
|
||||
end
|
||||
eval $nvm_ $argv
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user