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

46 lines
2.9 KiB
PowerShell

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'chgrp' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'chgrp'
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) {
'chgrp' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'report only when a change is made')
[CompletionResult]::new('--changes', 'changes', [CompletionResultType]::ParameterName, 'report only when a change is made')
[CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'output a diagnostic for every file processed')
[CompletionResult]::new('--verbose', 'verbose', [CompletionResultType]::ParameterName, 'output a diagnostic for every file processed')
[CompletionResult]::new('-R', 'R', [CompletionResultType]::ParameterName, 'operate on files and directories recursively')
[CompletionResult]::new('--recursive', 'recursive', [CompletionResultType]::ParameterName, 'operate on files and directories recursively')
[CompletionResult]::new('-H', 'H', [CompletionResultType]::ParameterName, 'if a command line argument is a symbolic link to a directory, traverse it')
[CompletionResult]::new('-L', 'L', [CompletionResultType]::ParameterName, 'traverse every symbolic link encountered in a directory')
[CompletionResult]::new('-P', 'P', [CompletionResultType]::ParameterName, 'do not traverse any symbolic links (default)')
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 'do not cross filesystem boundaries (requires recursive)')
[CompletionResult]::new('--same-filesystem', 'same-filesystem', [CompletionResultType]::ParameterName, 'do not cross filesystem boundaries (requires recursive)')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}