git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/cobra/shell_completions.md (about)

     1  # Generating shell completions
     2  
     3  Cobra can generate shell completions for multiple shells.
     4  The currently supported shells are:
     5  - Bash
     6  - Zsh
     7  - fish
     8  - PowerShell
     9  
    10  Cobra will automatically provide your program with a fully functional `completion` command,
    11  similarly to how it provides the `help` command.
    12  
    13  ## Creating your own completion command
    14  
    15  If you do not wish to use the default `completion` command, you can choose to
    16  provide your own, which will take precedence over the default one. (This also provides
    17  backwards-compatibility with programs that already have their own `completion` command.)
    18  
    19  If you are using the `cobra-cli` generator,
    20  which can be found at [spf13/cobra-cli](https://github.com/spf13/cobra-cli),
    21  you can create a completion command by running
    22  
    23  ```bash
    24  cobra-cli add completion
    25  ```
    26  and then modifying the generated `cmd/completion.go` file to look something like this
    27  (writing the shell script to stdout allows the most flexible use):
    28  
    29  ```go
    30  var completionCmd = &cobra.Command{
    31  	Use:   "completion [bash|zsh|fish|powershell]",
    32  	Short: "Generate completion script",
    33  	Long: fmt.Sprintf(`To load completions:
    34  
    35  Bash:
    36  
    37    $ source <(%[1]s completion bash)
    38  
    39    # To load completions for each session, execute once:
    40    # Linux:
    41    $ %[1]s completion bash > /etc/bash_completion.d/%[1]s
    42    # macOS:
    43    $ %[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
    44  
    45  Zsh:
    46  
    47    # If shell completion is not already enabled in your environment,
    48    # you will need to enable it.  You can execute the following once:
    49  
    50    $ echo "autoload -U compinit; compinit" >> ~/.zshrc
    51  
    52    # To load completions for each session, execute once:
    53    $ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
    54  
    55    # You will need to start a new shell for this setup to take effect.
    56  
    57  fish:
    58  
    59    $ %[1]s completion fish | source
    60  
    61    # To load completions for each session, execute once:
    62    $ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
    63  
    64  PowerShell:
    65  
    66    PS> %[1]s completion powershell | Out-String | Invoke-Expression
    67  
    68    # To load completions for every new session, run:
    69    PS> %[1]s completion powershell > %[1]s.ps1
    70    # and source this file from your PowerShell profile.
    71  `,cmd.Root().Name()),
    72  	DisableFlagsInUseLine: true,
    73  	ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
    74  	Args:                  cobra.ExactValidArgs(1),
    75  	Run: func(cmd *cobra.Command, args []string) {
    76  		switch args[0] {
    77  		case "bash":
    78  			cmd.Root().GenBashCompletion(os.Stdout)
    79  		case "zsh":
    80  			cmd.Root().GenZshCompletion(os.Stdout)
    81  		case "fish":
    82  			cmd.Root().GenFishCompletion(os.Stdout, true)
    83  		case "powershell":
    84  			cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
    85  		}
    86  	},
    87  }
    88  ```
    89  
    90  **Note:** The cobra generator may include messages printed to stdout, for example, if the config file is loaded; this will break the auto-completion script so must be removed.
    91  
    92  ## Adapting the default completion command
    93  
    94  Cobra provides a few options for the default `completion` command.  To configure such options you must set
    95  the `CompletionOptions` field on the *root* command.
    96  
    97  To tell Cobra *not* to provide the default `completion` command:
    98  ```
    99  rootCmd.CompletionOptions.DisableDefaultCmd = true
   100  ```
   101  
   102  To tell Cobra to mark the default `completion` command as *hidden*:
   103  ```
   104  rootCmd.CompletionOptions.HiddenDefaultCmd = true
   105  ```
   106  
   107  To tell Cobra *not* to provide the user with the `--no-descriptions` flag to the completion sub-commands:
   108  ```
   109  rootCmd.CompletionOptions.DisableNoDescFlag = true
   110  ```
   111  
   112  To tell Cobra to completely disable descriptions for completions:
   113  ```
   114  rootCmd.CompletionOptions.DisableDescriptions = true
   115  ```
   116  
   117  # Customizing completions
   118  
   119  The generated completion scripts will automatically handle completing commands and flags.  However, you can make your completions much more powerful by providing information to complete your program's nouns and flag values.
   120  
   121  ## Completion of nouns
   122  
   123  ### Static completion of nouns
   124  
   125  Cobra allows you to provide a pre-defined list of completion choices for your nouns using the `ValidArgs` field.
   126  For example, if you want `kubectl get [tab][tab]` to show a list of valid "nouns" you have to set them.
   127  Some simplified code from `kubectl get` looks like:
   128  
   129  ```go
   130  validArgs = []string{ "pod", "node", "service", "replicationcontroller" }
   131  
   132  cmd := &cobra.Command{
   133  	Use:     "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
   134  	Short:   "Display one or many resources",
   135  	Long:    get_long,
   136  	Example: get_example,
   137  	Run: func(cmd *cobra.Command, args []string) {
   138  		cobra.CheckErr(RunGet(f, out, cmd, args))
   139  	},
   140  	ValidArgs: validArgs,
   141  }
   142  ```
   143  
   144  Notice we put the `ValidArgs` field on the `get` sub-command. Doing so will give results like:
   145  
   146  ```bash
   147  $ kubectl get [tab][tab]
   148  node   pod   replicationcontroller   service
   149  ```
   150  
   151  #### Aliases for nouns
   152  
   153  If your nouns have aliases, you can define them alongside `ValidArgs` using `ArgAliases`:
   154  
   155  ```go
   156  argAliases = []string { "pods", "nodes", "services", "svc", "replicationcontrollers", "rc" }
   157  
   158  cmd := &cobra.Command{
   159      ...
   160  	ValidArgs:  validArgs,
   161  	ArgAliases: argAliases
   162  }
   163  ```
   164  
   165  The aliases are not shown to the user on tab completion, but they are accepted as valid nouns by
   166  the completion algorithm if entered manually, e.g. in:
   167  
   168  ```bash
   169  $ kubectl get rc [tab][tab]
   170  backend        frontend       database
   171  ```
   172  
   173  Note that without declaring `rc` as an alias, the completion algorithm would not know to show the list of
   174  replication controllers following `rc`.
   175  
   176  ### Dynamic completion of nouns
   177  
   178  In some cases it is not possible to provide a list of completions in advance.  Instead, the list of completions must be determined at execution-time. In a similar fashion as for static completions, you can use the `ValidArgsFunction` field to provide a Go function that Cobra will execute when it needs the list of completion choices for the nouns of a command.  Note that either `ValidArgs` or `ValidArgsFunction` can be used for a single cobra command, but not both.
   179  Simplified code from `helm status` looks like:
   180  
   181  ```go
   182  cmd := &cobra.Command{
   183  	Use:   "status RELEASE_NAME",
   184  	Short: "Display the status of the named release",
   185  	Long:  status_long,
   186  	RunE: func(cmd *cobra.Command, args []string) {
   187  		RunGet(args[0])
   188  	},
   189  	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   190  		if len(args) != 0 {
   191  			return nil, cobra.ShellCompDirectiveNoFileComp
   192  		}
   193  		return getReleasesFromCluster(toComplete), cobra.ShellCompDirectiveNoFileComp
   194  	},
   195  }
   196  ```
   197  Where `getReleasesFromCluster()` is a Go function that obtains the list of current Helm releases running on the Kubernetes cluster.
   198  Notice we put the `ValidArgsFunction` on the `status` sub-command. Let's assume the Helm releases on the cluster are: `harbor`, `notary`, `rook` and `thanos` then this dynamic completion will give results like:
   199  
   200  ```bash
   201  $ helm status [tab][tab]
   202  harbor notary rook thanos
   203  ```
   204  You may have noticed the use of `cobra.ShellCompDirective`.  These directives are bit fields allowing to control some shell completion behaviors for your particular completion.  You can combine them with the bit-or operator such as `cobra.ShellCompDirectiveNoSpace | cobra.ShellCompDirectiveNoFileComp`
   205  ```go
   206  // Indicates that the shell will perform its default behavior after completions
   207  // have been provided (this implies none of the other directives).
   208  ShellCompDirectiveDefault
   209  
   210  // Indicates an error occurred and completions should be ignored.
   211  ShellCompDirectiveError
   212  
   213  // Indicates that the shell should not add a space after the completion,
   214  // even if there is a single completion provided.
   215  ShellCompDirectiveNoSpace
   216  
   217  // Indicates that the shell should not provide file completion even when
   218  // no completion is provided.
   219  ShellCompDirectiveNoFileComp
   220  
   221  // Indicates that the returned completions should be used as file extension filters.
   222  // For example, to complete only files of the form *.json or *.yaml:
   223  //    return []string{"yaml", "json"}, ShellCompDirectiveFilterFileExt
   224  // For flags, using MarkFlagFilename() and MarkPersistentFlagFilename()
   225  // is a shortcut to using this directive explicitly.
   226  //
   227  ShellCompDirectiveFilterFileExt
   228  
   229  // Indicates that only directory names should be provided in file completion.
   230  // For example:
   231  //    return nil, ShellCompDirectiveFilterDirs
   232  // For flags, using MarkFlagDirname() is a shortcut to using this directive explicitly.
   233  //
   234  // To request directory names within another directory, the returned completions
   235  // should specify a single directory name within which to search. For example,
   236  // to complete directories within "themes/":
   237  //    return []string{"themes"}, ShellCompDirectiveFilterDirs
   238  //
   239  ShellCompDirectiveFilterDirs
   240  ```
   241  
   242  ***Note***: When using the `ValidArgsFunction`, Cobra will call your registered function after having parsed all flags and arguments provided in the command-line.  You therefore don't need to do this parsing yourself.  For example, when a user calls `helm status --namespace my-rook-ns [tab][tab]`, Cobra will call your registered `ValidArgsFunction` after having parsed the `--namespace` flag, as it would have done when calling the `RunE` function.
   243  
   244  #### Debugging
   245  
   246  Cobra achieves dynamic completion through the use of a hidden command called by the completion script.  To debug your Go completion code, you can call this hidden command directly:
   247  ```bash
   248  $ helm __complete status har<ENTER>
   249  harbor
   250  :4
   251  Completion ended with directive: ShellCompDirectiveNoFileComp # This is on stderr
   252  ```
   253  ***Important:*** If the noun to complete is empty (when the user has not yet typed any letters of that noun), you must pass an empty parameter to the `__complete` command:
   254  ```bash
   255  $ helm __complete status ""<ENTER>
   256  harbor
   257  notary
   258  rook
   259  thanos
   260  :4
   261  Completion ended with directive: ShellCompDirectiveNoFileComp # This is on stderr
   262  ```
   263  Calling the `__complete` command directly allows you to run the Go debugger to troubleshoot your code.  You can also add printouts to your code; Cobra provides the following functions to use for printouts in Go completion code:
   264  ```go
   265  // Prints to the completion script debug file (if BASH_COMP_DEBUG_FILE
   266  // is set to a file path) and optionally prints to stderr.
   267  cobra.CompDebug(msg string, printToStdErr bool) {
   268  cobra.CompDebugln(msg string, printToStdErr bool)
   269  
   270  // Prints to the completion script debug file (if BASH_COMP_DEBUG_FILE
   271  // is set to a file path) and to stderr.
   272  cobra.CompError(msg string)
   273  cobra.CompErrorln(msg string)
   274  ```
   275  ***Important:*** You should **not** leave traces that print directly to stdout in your completion code as they will be interpreted as completion choices by the completion script.  Instead, use the cobra-provided debugging traces functions mentioned above.
   276  
   277  ## Completions for flags
   278  
   279  ### Mark flags as required
   280  
   281  Most of the time completions will only show sub-commands. But if a flag is required to make a sub-command work, you probably want it to show up when the user types [tab][tab].  You can mark a flag as 'Required' like so:
   282  
   283  ```go
   284  cmd.MarkFlagRequired("pod")
   285  cmd.MarkFlagRequired("container")
   286  ```
   287  
   288  and you'll get something like
   289  
   290  ```bash
   291  $ kubectl exec [tab][tab]
   292  -c            --container=  -p            --pod=
   293  ```
   294  
   295  ### Specify dynamic flag completion
   296  
   297  As for nouns, Cobra provides a way of defining dynamic completion of flags.  To provide a Go function that Cobra will execute when it needs the list of completion choices for a flag, you must register the function using the `command.RegisterFlagCompletionFunc()` function.
   298  
   299  ```go
   300  flagName := "output"
   301  cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   302  	return []string{"json", "table", "yaml"}, cobra.ShellCompDirectiveDefault
   303  })
   304  ```
   305  Notice that calling `RegisterFlagCompletionFunc()` is done through the `command` with which the flag is associated.  In our example this dynamic completion will give results like so:
   306  
   307  ```bash
   308  $ helm status --output [tab][tab]
   309  json table yaml
   310  ```
   311  
   312  #### Debugging
   313  
   314  You can also easily debug your Go completion code for flags:
   315  ```bash
   316  $ helm __complete status --output ""
   317  json
   318  table
   319  yaml
   320  :4
   321  Completion ended with directive: ShellCompDirectiveNoFileComp # This is on stderr
   322  ```
   323  ***Important:*** You should **not** leave traces that print to stdout in your completion code as they will be interpreted as completion choices by the completion script.  Instead, use the cobra-provided debugging traces functions mentioned further above.
   324  
   325  ### Specify valid filename extensions for flags that take a filename
   326  
   327  To limit completions of flag values to file names with certain extensions you can either use the different `MarkFlagFilename()` functions or a combination of `RegisterFlagCompletionFunc()` and `ShellCompDirectiveFilterFileExt`, like so:
   328  ```go
   329  flagName := "output"
   330  cmd.MarkFlagFilename(flagName, "yaml", "json")
   331  ```
   332  or
   333  ```go
   334  flagName := "output"
   335  cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   336  	return []string{"yaml", "json"}, ShellCompDirectiveFilterFileExt})
   337  ```
   338  
   339  ### Limit flag completions to directory names
   340  
   341  To limit completions of flag values to directory names you can either use the `MarkFlagDirname()` functions or a combination of `RegisterFlagCompletionFunc()` and `ShellCompDirectiveFilterDirs`, like so:
   342  ```go
   343  flagName := "output"
   344  cmd.MarkFlagDirname(flagName)
   345  ```
   346  or
   347  ```go
   348  flagName := "output"
   349  cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   350  	return nil, cobra.ShellCompDirectiveFilterDirs
   351  })
   352  ```
   353  To limit completions of flag values to directory names *within another directory* you can use a combination of `RegisterFlagCompletionFunc()` and `ShellCompDirectiveFilterDirs` like so:
   354  ```go
   355  flagName := "output"
   356  cmd.RegisterFlagCompletionFunc(flagName, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   357  	return []string{"themes"}, cobra.ShellCompDirectiveFilterDirs
   358  })
   359  ```
   360  ### Descriptions for completions
   361  
   362  Cobra provides support for completion descriptions.  Such descriptions are supported for each shell
   363  (however, for bash, it is only available in the [completion V2 version](#bash-completion-v2)).
   364  For commands and flags, Cobra will provide the descriptions automatically, based on usage information.
   365  For example, using zsh:
   366  ```
   367  $ helm s[tab]
   368  search  -- search for a keyword in charts
   369  show    -- show information of a chart
   370  status  -- displays the status of the named release
   371  ```
   372  while using fish:
   373  ```
   374  $ helm s[tab]
   375  search  (search for a keyword in charts)  show  (show information of a chart)  status  (displays the status of the named release)
   376  ```
   377  
   378  Cobra allows you to add descriptions to your own completions.  Simply add the description text after each completion, following a `\t` separator.  This technique applies to completions returned by `ValidArgs`, `ValidArgsFunction` and `RegisterFlagCompletionFunc()`.  For example:
   379  ```go
   380  ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
   381  	return []string{"harbor\tAn image registry", "thanos\tLong-term metrics"}, cobra.ShellCompDirectiveNoFileComp
   382  }}
   383  ```
   384  or
   385  ```go
   386  ValidArgs: []string{"bash\tCompletions for bash", "zsh\tCompletions for zsh"}
   387  ```
   388  ## Bash completions
   389  
   390  ### Dependencies
   391  
   392  The bash completion script generated by Cobra requires the `bash_completion` package. You should update the help text of your completion command to show how to install the `bash_completion` package ([Kubectl docs](https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion))
   393  
   394  ### Aliases
   395  
   396  You can also configure `bash` aliases for your program and they will also support completions.
   397  
   398  ```bash
   399  alias aliasname=origcommand
   400  complete -o default -F __start_origcommand aliasname
   401  
   402  # and now when you run `aliasname` completion will make
   403  # suggestions as it did for `origcommand`.
   404  
   405  $ aliasname <tab><tab>
   406  completion     firstcommand   secondcommand
   407  ```
   408  ### Bash legacy dynamic completions
   409  
   410  For backward compatibility, Cobra still supports its bash legacy dynamic completion solution.
   411  Please refer to [Bash Completions](bash_completions.md) for details.
   412  
   413  ### Bash completion V2
   414  
   415  Cobra provides two versions for bash completion.  The original bash completion (which started it all!) can be used by calling
   416  `GenBashCompletion()` or `GenBashCompletionFile()`.
   417  
   418  A new V2 bash completion version is also available.  This version can be used by calling `GenBashCompletionV2()` or
   419  `GenBashCompletionFileV2()`.  The V2 version does **not** support the legacy dynamic completion
   420  (see [Bash Completions](bash_completions.md)) but instead works only with the Go dynamic completion
   421  solution described in this document.
   422  Unless your program already uses the legacy dynamic completion solution, it is recommended that you use the bash
   423  completion V2 solution which provides the following extra features:
   424  - Supports completion descriptions (like the other shells)
   425  - Small completion script of less than 300 lines (v1 generates scripts of thousands of lines; `kubectl` for example has a bash v1 completion script of over 13K lines)
   426  - Streamlined user experience thanks to a completion behavior aligned with the other shells 
   427  
   428  `Bash` completion V2 supports descriptions for completions. When calling `GenBashCompletionV2()` or `GenBashCompletionFileV2()`
   429  you must provide these functions with a parameter indicating if the completions should be annotated with a description; Cobra
   430  will provide the description automatically based on usage information.  You can choose to make this option configurable by
   431  your users.
   432  
   433  ```
   434  # With descriptions
   435  $ helm s[tab][tab]
   436  search  (search for a keyword in charts)           status  (display the status of the named release)
   437  show    (show information of a chart)
   438  
   439  # Without descriptions
   440  $ helm s[tab][tab]
   441  search  show  status
   442  ```
   443  **Note**: Cobra's default `completion` command uses bash completion V2.  If for some reason you need to use bash completion V1, you will need to implement your own `completion` command. 
   444  ## Zsh completions
   445  
   446  Cobra supports native zsh completion generated from the root `cobra.Command`.
   447  The generated completion script should be put somewhere in your `$fpath` and be named
   448  `_<yourProgram>`.  You will need to start a new shell for the completions to become available.
   449  
   450  Zsh supports descriptions for completions. Cobra will provide the description automatically,
   451  based on usage information. Cobra provides a way to completely disable such descriptions by
   452  using `GenZshCompletionNoDesc()` or `GenZshCompletionFileNoDesc()`. You can choose to make
   453  this a configurable option to your users.
   454  ```
   455  # With descriptions
   456  $ helm s[tab]
   457  search  -- search for a keyword in charts
   458  show    -- show information of a chart
   459  status  -- displays the status of the named release
   460  
   461  # Without descriptions
   462  $ helm s[tab]
   463  search  show  status
   464  ```
   465  *Note*: Because of backward-compatibility requirements, we were forced to have a different API to disable completion descriptions between `zsh` and `fish`.
   466  
   467  ### Limitations
   468  
   469  * Custom completions implemented in Bash scripting (legacy) are not supported and will be ignored for `zsh` (including the use of the `BashCompCustom` flag annotation).
   470    * You should instead use `ValidArgsFunction` and `RegisterFlagCompletionFunc()` which are portable to the different shells (`bash`, `zsh`, `fish`, `powershell`).
   471  * The function `MarkFlagCustom()` is not supported and will be ignored for `zsh`.
   472    * You should instead use `RegisterFlagCompletionFunc()`.
   473  
   474  ### Zsh completions standardization
   475  
   476  Cobra 1.1 standardized its zsh completion support to align it with its other shell completions.  Although the API was kept backward-compatible, some small changes in behavior were introduced.
   477  Please refer to [Zsh Completions](zsh_completions.md) for details.
   478  
   479  ## fish completions
   480  
   481  Cobra supports native fish completions generated from the root `cobra.Command`.  You can use the `command.GenFishCompletion()` or `command.GenFishCompletionFile()` functions. You must provide these functions with a parameter indicating if the completions should be annotated with a description; Cobra will provide the description automatically based on usage information.  You can choose to make this option configurable by your users.
   482  ```
   483  # With descriptions
   484  $ helm s[tab]
   485  search  (search for a keyword in charts)  show  (show information of a chart)  status  (displays the status of the named release)
   486  
   487  # Without descriptions
   488  $ helm s[tab]
   489  search  show  status
   490  ```
   491  *Note*: Because of backward-compatibility requirements, we were forced to have a different API to disable completion descriptions between `zsh` and `fish`.
   492  
   493  ### Limitations
   494  
   495  * Custom completions implemented in bash scripting (legacy) are not supported and will be ignored for `fish` (including the use of the `BashCompCustom` flag annotation).
   496    * You should instead use `ValidArgsFunction` and `RegisterFlagCompletionFunc()` which are portable to the different shells (`bash`, `zsh`, `fish`, `powershell`).
   497  * The function `MarkFlagCustom()` is not supported and will be ignored for `fish`.
   498    * You should instead use `RegisterFlagCompletionFunc()`.
   499  * The following flag completion annotations are not supported and will be ignored for `fish`:
   500    * `BashCompFilenameExt` (filtering by file extension)
   501    * `BashCompSubdirsInDir` (filtering by directory)
   502  * The functions corresponding to the above annotations are consequently not supported and will be ignored for `fish`:
   503    * `MarkFlagFilename()` and `MarkPersistentFlagFilename()` (filtering by file extension)
   504    * `MarkFlagDirname()` and `MarkPersistentFlagDirname()` (filtering by directory)
   505  * Similarly, the following completion directives are not supported and will be ignored for `fish`:
   506    * `ShellCompDirectiveFilterFileExt` (filtering by file extension)
   507    * `ShellCompDirectiveFilterDirs` (filtering by directory)
   508  
   509  ## PowerShell completions
   510  
   511  Cobra supports native PowerShell completions generated from the root `cobra.Command`. You can use the `command.GenPowerShellCompletion()` or `command.GenPowerShellCompletionFile()` functions. To include descriptions use `command.GenPowerShellCompletionWithDesc()` and `command.GenPowerShellCompletionFileWithDesc()`. Cobra will provide the description automatically based on usage information. You can choose to make this option configurable by your users.
   512  
   513  The script is designed to support all three PowerShell completion modes:
   514  
   515  * TabCompleteNext (default windows style - on each key press the next option is displayed)
   516  * Complete (works like bash)
   517  * MenuComplete (works like zsh)
   518  
   519  You set the mode with `Set-PSReadLineKeyHandler -Key Tab -Function <mode>`. Descriptions are only displayed when using the `Complete` or `MenuComplete` mode.
   520  
   521  Users need PowerShell version 5.0 or above, which comes with Windows 10 and can be downloaded separately for Windows 7 or 8.1. They can then write the completions to a file and source this file from their PowerShell profile, which is referenced by the `$Profile` environment variable. See `Get-Help about_Profiles` for more info about PowerShell profiles.
   522  
   523  ```
   524  # With descriptions and Mode 'Complete'
   525  $ helm s[tab]
   526  search  (search for a keyword in charts)  show  (show information of a chart)  status  (displays the status of the named release)
   527  
   528  # With descriptions and Mode 'MenuComplete' The description of the current selected value will be displayed below the suggestions.
   529  $ helm s[tab]
   530  search    show     status  
   531  
   532  search for a keyword in charts
   533  
   534  # Without descriptions
   535  $ helm s[tab]
   536  search  show  status
   537  ```
   538  ### Aliases
   539  
   540  You can also configure `powershell` aliases for your program and they will also support completions.
   541  
   542  ```
   543  $ sal aliasname origcommand
   544  $ Register-ArgumentCompleter -CommandName 'aliasname' -ScriptBlock $__origcommandCompleterBlock
   545  
   546  # and now when you run `aliasname` completion will make
   547  # suggestions as it did for `origcommand`.
   548  
   549  $ aliasname <tab>
   550  completion     firstcommand   secondcommand
   551  ```
   552  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.
   553  
   554  ### Limitations
   555  
   556  * Custom completions implemented in bash scripting (legacy) are not supported and will be ignored for `powershell` (including the use of the `BashCompCustom` flag annotation).
   557    * You should instead use `ValidArgsFunction` and `RegisterFlagCompletionFunc()` which are portable to the different shells (`bash`, `zsh`, `fish`, `powershell`).
   558  * The function `MarkFlagCustom()` is not supported and will be ignored for `powershell`.
   559    * You should instead use `RegisterFlagCompletionFunc()`.
   560  * The following flag completion annotations are not supported and will be ignored for `powershell`:
   561    * `BashCompFilenameExt` (filtering by file extension)
   562    * `BashCompSubdirsInDir` (filtering by directory)
   563  * The functions corresponding to the above annotations are consequently not supported and will be ignored for `powershell`:
   564    * `MarkFlagFilename()` and `MarkPersistentFlagFilename()` (filtering by file extension)
   565    * `MarkFlagDirname()` and `MarkPersistentFlagDirname()` (filtering by directory)
   566  * Similarly, the following completion directives are not supported and will be ignored for `powershell`:
   567    * `ShellCompDirectiveFilterFileExt` (filtering by file extension)
   568    * `ShellCompDirectiveFilterDirs` (filtering by directory)