Last active
December 16, 2023 15:07
-
-
Save doggy8088/2bf2a46f7e65ae4197b6092df3835f21 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
# winget parameter completion | |
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { | |
param($wordToComplete, $commandAst, $cursorPosition) | |
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() | |
$Local:word = $wordToComplete.Replace('"', '""') | |
$Local:ast = $commandAst.ToString().Replace('"', '""') | |
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
# PowerShell parameter completion shim for the dotnet CLI | |
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { | |
param($commandName, $wordToComplete, $cursorPosition) | |
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
# PowerShell parameter completion shim for the npm CLI | |
Register-ArgumentCompleter -Native -CommandName npm -ScriptBlock { | |
param($wordToComplete, $commandAst, $cursorPosition) | |
$Local:ast = $commandAst.ToString().Replace(' ', '') | |
if ($Local:ast -eq 'npm') { | |
$command = 'run install start' | |
$array = $command.Split(' ') | |
$array | | |
Where-Object { $_ -like "$wordToComplete*" } | | |
ForEach-Object { | |
New-Object -Type System.Management.Automation.CompletionResult -ArgumentList $_ | |
} | |
} | |
if ($Local:ast -eq 'npmrun') { | |
$scripts = (Get-Content .\package.json | ConvertFrom-Json).scripts | |
$scripts | | |
Get-Member -MemberType NoteProperty | | |
Where-Object { $_.Name -like "$wordToComplete*" } | | |
ForEach-Object { | |
New-Object -Type System.Management.Automation.CompletionResult -ArgumentList $_.Name | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment