Skip to content

Instantly share code, notes, and snippets.

@n0mn0m
Created September 8, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0mn0m/34e1feb46721b0a084982ad33bc1cd5d to your computer and use it in GitHub Desktop.
Save n0mn0m/34e1feb46721b0a084982ad33bc1cd5d to your computer and use it in GitHub Desktop.
fish nvm
function nvm-fast
set -q NVM_DIR ; or set -l NVM_DIR ~/.nvm
set -l brigand_nvm_fish_path $NVM_DIR/versions/node
if test (count $argv[1]) -lt 1
echo 'nvm-fast: at least one argument is required'
end
set -l command $argv[1]
if test $command = 'use'
set target_version "unknown"
if test (count $argv) -eq 1
if test -f .nvmrc
set target_version (cat .nvmrc)
else
echo "Error: No version provided and no .nvmrc found"
return
end
else
set target_version $argv[2]
end
set -l target_version $target_version
set -l matched_version (bash -c "source $NVM_DIR/nvm.sh --no-use; nvm_version $target_version")
if test -z $matched_version -o $matched_version = 'N/A'
echo "No version installed for $target_version, run nvm install $target_version"
echo "Installed versions: "
for file in $brigand_nvm_fish_path/v*
echo ' -' $file
end
else
set -l new_path (string match -ev "$brigand_nvm_fish_path" $PATH)
if test $matched_version != 'system'
set new_path $brigand_nvm_fish_path/$matched_version/bin $new_path
end
set -gx PATH $new_path
set -gx NVM_BIN (which node)
end
else
bash -c "source $NVM_DIR/nvm.sh --no-use; nvm $argv"
set -gx NVM_BIN (which node)
end
end
function nvm
switch "$FISH_VERSION"
case 2.0.0 2.1.0 2.1.1 2.1.2 2.2.0 2.2b1 2.3.0 2.3.1 2.3b1 2.3b2 2.4.0 2.4b1 2.5.0 2.5b1
echo "You need fish 2.6.0 or higher to use fast-nvm-fish." 1>&2
return 1
end
nvm-fast $argv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment