Created
April 29, 2023 15:57
-
-
Save asportnoy/d3834347aee5e81390b9671305a4536c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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