Skip to content

Commit

Permalink
Allow user to add completion for powershell alias
Browse files Browse the repository at this point in the history
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 spf13/cobra#1621
  • Loading branch information
marckhouzam authored and hoshsadiq committed Jan 3, 2023
1 parent b7ff44c commit 34d3bfd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions site/content/completions/powershell.md
Expand Up @@ -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 <tab>
completion firstcommand secondcommand
```
The name of the completer block variable is of the form `$__<programName>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`:
Expand Down

0 comments on commit 34d3bfd

Please sign in to comment.