From 1eac915fbaa4d5ba73441904305cc09d86ba1627 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Sat, 15 Nov 2014 22:41:05 +0100 Subject: [PATCH] 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. --- nvm.fish | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 nvm.fish diff --git a/nvm.fish b/nvm.fish new file mode 100644 index 0000000..a4072bc --- /dev/null +++ b/nvm.fish @@ -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