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

44 lines
2.7 KiB
PowerShell

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'head' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'head'
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) {
'head' {
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Count n number of lines (or bytes if -c is specified).')
[CompletionResult]::new('--lines', 'lines', [CompletionResultType]::ParameterName, 'Count n number of lines (or bytes if -c is specified).')
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'C')
[CompletionResult]::new('--color', 'color', [CompletionResultType]::ParameterName, 'color')
[CompletionResult]::new('-1', '1', [CompletionResultType]::ParameterName, '1')
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Count bytes instead of lines')
[CompletionResult]::new('--bytes', 'bytes', [CompletionResultType]::ParameterName, 'Count bytes instead of lines')
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Disable printing a header. Overrides -c')
[CompletionResult]::new('--quiet', 'quiet', [CompletionResultType]::ParameterName, 'Disable printing a header. Overrides -c')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Each file is preceded by a header consisting of the string "==> XXX <==" where "XXX" is the name of the file.')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'Each file is preceded by a header consisting of the string "==> XXX <==" where "XXX" is the name of the file.')
[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
}