|  | 
| 53 | 53 |         complete -fa "(__fish_complete_pip)" -c {prog} | 
| 54 | 54 |     """, | 
| 55 | 55 |     "powershell": """ | 
| 56 |  | -        if ((Test-Path Function:\\TabExpansion) -and -not ` | 
| 57 |  | -            (Test-Path Function:\\_pip_completeBackup)) {{ | 
| 58 |  | -            Rename-Item Function:\\TabExpansion _pip_completeBackup | 
| 59 |  | -        }} | 
| 60 |  | -        function TabExpansion($line, $lastWord) {{ | 
| 61 |  | -            $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() | 
| 62 |  | -            if ($lastBlock.StartsWith("{prog} ")) {{ | 
| 63 |  | -                $Env:COMP_WORDS=$lastBlock | 
| 64 |  | -                $Env:COMP_CWORD=$lastBlock.Split().Length - 1 | 
| 65 |  | -                $Env:PIP_AUTO_COMPLETE=1 | 
| 66 |  | -                (& {prog}).Split() | 
| 67 |  | -                Remove-Item Env:COMP_WORDS | 
| 68 |  | -                Remove-Item Env:COMP_CWORD | 
| 69 |  | -                Remove-Item Env:PIP_AUTO_COMPLETE | 
| 70 |  | -            }} | 
| 71 |  | -            elseif (Test-Path Function:\\_pip_completeBackup) {{ | 
| 72 |  | -                # Fall back on existing tab expansion | 
| 73 |  | -                _pip_completeBackup $line $lastWord | 
|  | 56 | +        Register-ArgumentCompleter -Native -CommandName '{prog}' -ScriptBlock {{ | 
|  | 57 | +            param($commandName, $commandAst, $cursorPosition) | 
|  | 58 | +            $commandElements = $commandAst.CommandElements | 
|  | 59 | +            $command = @( | 
|  | 60 | +                '{prog}' | 
|  | 61 | +                for ($i = 1; $i -lt $commandElements.Count; $i++) {{ | 
|  | 62 | +                    $element = $commandElements[$i] | 
|  | 63 | +                    if ($element -isnot [StringConstantExpressionAst] -or | 
|  | 64 | +                        $element.StringConstantType -ne [StringConstantType]::BareWord -or | 
|  | 65 | +                        $element.Value.StartsWith('-')) {{ | 
|  | 66 | +                        break | 
|  | 67 | +                    }} | 
|  | 68 | +                    $element.Value | 
|  | 69 | +                }} | 
|  | 70 | +            ) -join ' ' | 
|  | 71 | +             | 
|  | 72 | +            $Env:COMP_WORDS = $command | 
|  | 73 | +            $Env:COMP_CWORD = $commandElements.Count - 1 | 
|  | 74 | +            $Env:PIP_AUTO_COMPLETE = 1 | 
|  | 75 | +            $completions = & {prog} 2>$null | 
|  | 76 | +            Remove-Item Env:COMP_WORDS | 
|  | 77 | +            Remove-Item Env:COMP_CWORD   | 
|  | 78 | +            Remove-Item Env:PIP_AUTO_COMPLETE | 
|  | 79 | +             | 
|  | 80 | +            if ($completions) {{ | 
|  | 81 | +                $completions.Split() | ForEach-Object {{ | 
|  | 82 | +                    [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | 
|  | 83 | +                }} | 
| 74 | 84 |             }} | 
| 75 | 85 |         }} | 
| 76 | 86 |     """, | 
| 77 | 87 | } | 
| 78 | 88 | 
 | 
| 79 |  | - | 
| 80 | 89 | class CompletionCommand(Command): | 
| 81 | 90 |     """A helper command to be used for command completion.""" | 
| 82 | 91 | 
 | 
|  | 
0 commit comments