Skip to content

Commit c6fe2d4

Browse files
authored
Improve zsh completion documentation (#1169)
Signed-off-by: Marc Khouzam <[email protected]>
1 parent 19e41cf commit c6fe2d4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

shell_completions.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@ MacOS:
3333
3434
Zsh:
3535
36-
$ source <(yourprogram completion zsh)
36+
# If shell completion is not already enabled in your environment you will need
37+
# to enable it. You can execute the following once:
38+
39+
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
3740
3841
# To load completions for each session, execute once:
3942
$ yourprogram completion zsh > "${fpath[1]}/_yourprogram"
4043
44+
# You will need to start a new shell for this setup to take effect.
45+
4146
Fish:
4247
4348
$ yourprogram completion fish | source
@@ -363,7 +368,7 @@ Please refer to [Bash Completions](bash_completions.md) for details.
363368

364369
Cobra supports native Zsh completion generated from the root `cobra.Command`.
365370
The generated completion script should be put somewhere in your `$fpath` and be named
366-
`_<yourProgram>`.
371+
`_<yourProgram>`. You will need to start a new shell for the completions to become available.
367372

368373
Zsh supports descriptions for completions. Cobra will provide the description automatically,
369374
based on usage information. Cobra provides a way to completely disable such descriptions by

zsh_completions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ See further below for more details on these deprecations.
2222
|Old behavior|New behavior|
2323
|---|---|
2424
|No file completion by default (opposite of bash)|File completion by default; use `ValidArgsFunction` with `ShellCompDirectiveNoFileComp` to turn off file completion on a per-argument basis|
25+
|Completion of flag names without the `-` prefix having been typed|Flag names are only completed if the user has typed the first `-`|
2526
`cmd.MarkZshCompPositionalArgumentFile(pos, []string{})` used to turn on file completion on a per-argument position basis|File completion for all arguments by default; `cmd.MarkZshCompPositionalArgumentFile()` is **deprecated** and silently ignored|
2627
|`cmd.MarkZshCompPositionalArgumentFile(pos, glob[])` used to turn on file completion **with glob filtering** on a per-argument position basis (zsh-specific)|`cmd.MarkZshCompPositionalArgumentFile()` is **deprecated** and silently ignored; use `ValidArgsFunction` with `ShellCompDirectiveFilterFileExt` for file **extension** filtering (not full glob filtering)|
2728
|`cmd.MarkZshCompPositionalArgumentWords(pos, words[])` used to provide completion choices on a per-argument position basis (zsh-specific)|`cmd.MarkZshCompPositionalArgumentWords()` is **deprecated** and silently ignored; use `ValidArgsFunction` to achieve the same behavior|

0 commit comments

Comments
 (0)