shitbox/pkg/usr/share/pwsh/completions/_fold.ps1

41 lines
2.1 KiB
PowerShell

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'fold' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'fold'
for ($i = 1; $i -lt $commandElements.Count; $i++) {
$element = $commandElements[$i]
if ($element -isnot [StringConstantExpressionAst] -or
$element.StringConstantType -ne [StringConstantType]::BareWord -or
$element.Value.StartsWith('-') -or
$element.Value -eq $wordToComplete) {
break
}
$element.Value
}) -join ';'
$completions = @(switch ($command) {
'fold' {
[CompletionResult]::new('-w', 'w', [CompletionResultType]::ParameterName, 'Use width columns')
[CompletionResult]::new('--width', 'width', [CompletionResultType]::ParameterName, 'Use width columns')
[CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'Count bytes rather than columns')
[CompletionResult]::new('--bytes', 'bytes', [CompletionResultType]::ParameterName, 'Count bytes rather than columns')
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'Break at spaces')
[CompletionResult]::new('--spaces', 'spaces', [CompletionResultType]::ParameterName, 'Break at spaces')
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'Optimal fit')
[CompletionResult]::new('--optimal', 'optimal', [CompletionResultType]::ParameterName, 'Optimal fit')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
break
}
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}