Aws-cli: auto_compeleter support for powershell including windows.

Created on 23 Jun 2020  路  3Comments  路  Source: aws/aws-cli

Is your feature request related to a problem? Please describe.
Tab completion support for Powershell for all supported platforms including windows for version 2.

Describe the solution you'd like
when calling aws_completion.exe "s3" 2 have it actually output something

Describe alternatives you've considered

I have tried all sorts of combinations of cursor position and text, and I have been unsuccessful to get any output on windows.

Additional context
if aws_completer would output correctly then something like this would make it work in Powershell.

# PowerShell parameter completion for AWS
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
        aws_completer.exe "$wordToComplete" $cursorPosition | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
    }
}
feature-request

Most helpful comment

This works 馃殌

# AWS CLI
# PowerShell parameter completion shim for the aws CLI
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
        Set-Item -Path Env:COMP_LINE -Value $wordToComplete
        Set-Item -Path Env:COMP_POINT -Value $cursorPosition
        aws_completer.exe | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
    }
}

All 3 comments

Thanks @rlove for the feature request! Currently only Unix-like operating systems are supported for tab completion, so this would be a useful new feature for Windows users.

@kdaily what is needed to make this work? I was previously able to configure aws 1.x to support completion via Register-ArgumentCompleter (example below)

# AWS CLI
# PowerShell parameter completion shim for the aws CLI
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
    $completer = "C:\Python\lib\site-packages\awscli\completer.pyc"
    python.exe $completer "$wordToComplete" $cursorPosition | ForEach-Object {
        [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
    }
}

In the v2 branch, which is the current completer?

Edit:

Is as it simple making https://github.com/aws/aws-cli/blob/v2/bin/aws_completer support windows?

def main():
    # bash exports COMP_LINE and COMP_POINT, tcsh COMMAND_LINE only
    command_line = (
        os.environ.get('COMP_LINE') or os.environ.get('COMMAND_LINE') or ''
    )
    command_index = int(os.environ.get('COMP_POINT') or len(command_line))

This works 馃殌

# AWS CLI
# PowerShell parameter completion shim for the aws CLI
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
        Set-Item -Path Env:COMP_LINE -Value $wordToComplete
        Set-Item -Path Env:COMP_POINT -Value $cursorPosition
        aws_completer.exe | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
    }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

KimberleySDU picture KimberleySDU  路  3Comments

vadimkim picture vadimkim  路  3Comments

pawelkilian picture pawelkilian  路  3Comments

alexejk picture alexejk  路  3Comments

ikim23 picture ikim23  路  3Comments