Created
November 7, 2024 18:02
-
-
Save milnak/aca35e41e8c077993d7637afd89eedf1 to your computer and use it in GitHub Desktop.
Complete scoop arguments (with ctrl-space) in PowerShell
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
$argumentCompleterScriptBlock = { | |
param($wordToComplete, $commandAst, $cursorPosition) | |
$commands = ` | |
@{Text = 'alias'; Tip = 'Manage scoop aliases' }, ` | |
@{Text = 'bucket'; Tip = 'Manage Scoop buckets' }, ` | |
@{Text = 'cache'; Tip = 'Show or clear the download cache' }, ` | |
@{Text = 'cat'; Tip = 'Show content of specified manifest.' }, ` | |
@{Text = 'checkup'; Tip = 'Check for potential problems' }, ` | |
@{Text = 'cleanup'; Tip = 'Cleanup apps by removing old versions' }, ` | |
@{Text = 'config'; Tip = 'Get or set configuration values' }, ` | |
@{Text = 'create'; Tip = 'Create a custom app manifest' }, ` | |
@{Text = 'depends'; Tip = 'List dependencies for an app, in the order they''ll be installed' }, ` | |
@{Text = 'download'; Tip = 'Download apps in the cache folder and verify hashes' }, ` | |
@{Text = 'export'; Tip = 'Exports installed apps, buckets (and optionally configs) in JSON format' }, ` | |
@{Text = 'help'; Tip = 'Show help for a command' }, ` | |
@{Text = 'hold'; Tip = 'Hold an app to disable updates' }, ` | |
@{Text = 'home'; Tip = 'Opens the app homepage' }, ` | |
@{Text = 'import'; Tip = 'Imports apps, buckets and configs from a Scoopfile in JSON format' }, ` | |
@{Text = 'info'; Tip = 'Display information about an app' }, ` | |
@{Text = 'install'; Tip = 'Install apps' }, ` | |
@{Text = 'list'; Tip = 'List installed apps' }, ` | |
@{Text = 'prefix'; Tip = 'Returns the path to the specified app' }, ` | |
@{Text = 'reset'; Tip = 'Reset an app to resolve conflicts' }, ` | |
@{Text = 'search'; Tip = 'Search available apps' }, ` | |
@{Text = 'shim'; Tip = 'Manipulate Scoop shims' }, ` | |
@{Text = 'status'; Tip = 'Show status and check for new app versions' }, ` | |
@{Text = 'unhold'; Tip = 'Unhold an app to enable updates' }, ` | |
@{Text = 'uninstall'; Tip = 'Uninstall an app' }, ` | |
@{Text = 'update'; Tip = 'Update apps, or Scoop itself' }, ` | |
@{Text = 'virustotal'; Tip = 'Look for app''s hash or url on virustotal.com' }, ` | |
@{Text = 'which'; Tip = 'Locate a shim/executable (similar to ''which'' on Linux)' } ` | |
# Write-Host "`n`n`n`n" | |
# Write-Host -ForegroundColor Yellow "wordToComplete = '$wordToComplete'" | |
# Write-Host -ForegroundColor Yellow "commandAst = '$commandAst'" | |
# Write-Host -ForegroundColor Yellow "cursorPosition = '$cursorPosition'" | |
$command, $params = $commandAst.ToString() -split " ", 2 | |
$params = $params -split " " | |
if ( $wordToComplete -ne "" -and $wordToComplete -notlike "-*" ) { | |
$params = ($params | Select-Object -SkipLast 1 ) | |
} | |
# & $command --completion-bash $params | Where-Object { $_ -like "$wordToComplete*" } | | |
$commands | ForEach-Object { | |
# completionText, listItemText, resultType, toolTip | |
[Management.Automation.CompletionResult]::new($_.Text, $_.Text, 'ParameterValue', $_.Tip) | |
} | |
} | |
Register-ArgumentCompleter -Native -CommandName scoop.exe -ScriptBlock $argumentCompleterScriptBlock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment