Skip to content

Instantly share code, notes, and snippets.

@krymtkts
Last active July 18, 2021 22:24
Show Gist options
  • Save krymtkts/d6f5d7ca97c49a62432b536a5e39ae44 to your computer and use it in GitHub Desktop.
Save krymtkts/d6f5d7ca97c49a62432b536a5e39ae44 to your computer and use it in GitHub Desktop.
# This idea was inspired by https://github.com/aws/aws-cli/issues/5309#issuecomment-693941619
$awsCompleter = Get-Command -Name aws_completer -ErrorAction SilentlyContinue
if ($awsCompleter) {
# for PyPI installation.
if ($awsCompleter.Name -notlike '*.exe' ) {
$f = { python $awsCompleter.Source }
}
else {
$f = { & $awsCompleter.Name }
}
Register-ArgumentCompleter -Native -CommandName aws -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
if ("$commandAst" -eq 'aws') {
# complement the deleted space so that aws_completer lists all services.
$compLine = "$commandAst "
}
else {
$compLine = $commandAst
}
$env:COMP_LINE = $compLine
$env:COMP_POINT = $cursorPosition
& $f | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
Remove-Item env:\COMP_LINE
Remove-Item env:\COMP_POINT
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment