From 34d3bfdaded2f0dacbff39365284a11971fd865a Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 3 Jan 2023 02:17:19 +0000 Subject: [PATCH] Allow user to add completion for powershell alias When a user has an alias in powershell, she will need to register that alias for completion. To make that possible, we store the completion logic into a scriptblock variable which can easily be accessed by the user to register aliases. For example, if the user defines an alias for `helm`: PS> sal h helm she will need to register the alias like so: PS> Register-ArgumentCompleter -CommandName 'h' -ScriptBlock $__helmCompleterBlock Merge https://github.com/spf13/cobra/pull/1621 --- site/content/completions/powershell.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/site/content/completions/powershell.md b/site/content/completions/powershell.md index 667e2e1..b6a312e 100644 --- a/site/content/completions/powershell.md +++ b/site/content/completions/powershell.md @@ -36,6 +36,20 @@ $ helm s[tab] search show status ``` +### Aliases + +You can also configure `powershell` aliases for your program, and they will also support completions. + +``` +$ sal aliasname origcommand +$ Register-ArgumentCompleter -CommandName 'aliasname' -ScriptBlock $__origcommandCompleterBlock +# and now when you run `aliasname` completion will make +# suggestions as it did for `origcommand`. +$ aliasname +completion firstcommand secondcommand +``` +The name of the completer block variable is of the form `$__CompleterBlock` where every `-` and `:` in the program name have been replaced with `_`, to respect powershell naming syntax. + ### Limitations * The following flag completion annotations are not supported and will be ignored for `powershell`: