46 lines
2.6 KiB
PowerShell
46 lines
2.6 KiB
PowerShell
|
|
using namespace System.Management.Automation
|
|
using namespace System.Management.Automation.Language
|
|
|
|
Register-ArgumentCompleter -Native -CommandName 'cut' -ScriptBlock {
|
|
param($wordToComplete, $commandAst, $cursorPosition)
|
|
|
|
$commandElements = $commandAst.CommandElements
|
|
$command = @(
|
|
'cut'
|
|
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) {
|
|
'cut' {
|
|
[CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'select only these bytes')
|
|
[CompletionResult]::new('--bytes', 'bytes', [CompletionResultType]::ParameterName, 'select only these bytes')
|
|
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'select only these characters')
|
|
[CompletionResult]::new('--characters', 'characters', [CompletionResultType]::ParameterName, 'select only these characters')
|
|
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'select only these fields')
|
|
[CompletionResult]::new('--fields', 'fields', [CompletionResultType]::ParameterName, 'select only these fields')
|
|
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'use DELIM instead of TAB for field delimiter')
|
|
[CompletionResult]::new('--delimiter', 'delimiter', [CompletionResultType]::ParameterName, 'use DELIM instead of TAB for field delimiter')
|
|
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'ignored')
|
|
[CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 's')
|
|
[CompletionResult]::new('--only-delimited', 'only-delimited', [CompletionResultType]::ParameterName, 'only-delimited')
|
|
[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
|
|
}
|