Created
February 9, 2025 19:58
-
-
Save maxisam/9b5ece770c62e6a3ee978b4e671138d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$origNvm = Get-Command nvm -CommandType Application -ErrorAction SilentlyContinue | |
if ($origNvm) { Set-Alias nvm_external $origNvm.Path } | |
function nvmFunc { | |
param( | |
[string]$Argument, | |
[string]$Version = "" | |
) | |
function Get-NvmVersion { | |
if (Test-Path ".nvmrc") { | |
return (Get-Content .nvmrc).Trim() | |
} | |
elseif (Test-Path ".node-version") { | |
return (Get-Content .node-version).Trim() | |
} | |
else { | |
Write-Warning "No .nvmrc or .node-version file found" | |
return $null | |
} | |
} | |
if ($Argument -eq "install" -and $Version -eq "") { | |
$ver = Get-NvmVersion | |
if ($ver) { & nvm install $ver } | |
} | |
elseif ($Argument -eq "use") { | |
if ($Version -eq "") { | |
$ver = Get-NvmVersion | |
} | |
else { | |
$ver = $Version | |
} | |
if ($ver) { & cmd /c nvm use $ver } | |
} | |
else { | |
& nvm_external $Argument | |
} | |
} | |
Set-alias nvm nvmFunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment