Enable CLI Completion in PowerShell using Bash Completions
With this article I will go over how I enabled Pulumi Command-Line Completion to PowerShell. Since Pulumi does not have built in completion generation for PowerShell I had to find another way to get this sweet feature. Since Pulumi does support Bash CLI Completion generation we can use this generation to do it!
How It's Done
Here is a high-level overview of what will be needed to get completions running for Pulumi:
Install the PSBashCompletions PowerShell Module
Make sure bash.exe is in our path.
Generate our bash completion script, in our case I am using Pulumi's.
Register our bash completion script with the PSBashCompletions Module.
We rely heavily on the article PSBashCompletions: Bash Argument Completion in PowerShell from Travis Illig, he published the PSBashCompletions PowerShell Module as part of this article. The article states we need to have the bash.exe in our path, this comes along with Git for Windows, so install that if you need too.
Installing BashArgumentCompleter use this command:
Install-Module -Name PSBashCompletions -Scope CurrentUser
To generate the bash completion and output it into a file for Pulumi I used the below PowerShell command:
pulumi gen-completion bash > $PROFILE_PATH/.pulumi_completions
To register our bash completion script with Pulumi:
Register-BashArgumentCompleter pulumi "$PROFILE_PATH/.pulumi_completions"
Testing out the bash completion: