Skip to content

Instantly share code, notes, and snippets.

@asportnoy
Created April 29, 2023 15:57
Show Gist options
  • Save asportnoy/d3834347aee5e81390b9671305a4536c to your computer and use it in GitHub Desktop.
Save asportnoy/d3834347aee5e81390b9671305a4536c to your computer and use it in GitHub Desktop.
function nvm-exec
# match version
set ver "$argv[1]"
if not test "$ver"
echo "Version is missing"
return 1
end
# logic from nvm command to parse version
_nvm_list | string match --entire --regex -- (_nvm_version_match $ver) | read ver __
if not test "$ver"
echo "Version $argv[1] is not installed"
return 1
end
# command is 2nd arg (eg node, npm)
set cmd "$argv[2]"
if not test "$cmd"
echo "Command is missing"
return 1
end
# get path to command within version
set cmd_path "$nvm_data/$ver/bin/$cmd"
# check if command exists
if not test -e "$cmd_path"
echo "Command $cmd does not exist"
return 1
end
# execute command
$cmd_path $argv[3..-1]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment