Skip to content

Commit 782932b

Browse files
authored
Merge pull request cli#2636 from cli/docs-completion
Improve `completion` docs for bash, zsh, fish
2 parents 3d2d9e7 + 9d50221 commit 782932b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

pkg/cmd/completion/completion.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,44 @@ func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command {
1414
var shellType string
1515

1616
cmd := &cobra.Command{
17-
Use: "completion",
17+
Use: "completion -s <shell>",
1818
Short: "Generate shell completion scripts",
19-
Long: heredoc.Doc(`
19+
Long: heredoc.Docf(`
2020
Generate shell completion scripts for GitHub CLI commands.
2121
22-
The output of this command will be computer code and is meant to be saved to a
23-
file or immediately evaluated by an interactive shell.
22+
When installing GitHub CLI through a package manager, it's possible that
23+
no additional shell configuration is necessary to gain completion support. For
24+
Homebrew, see https://docs.brew.sh/Shell-Completion
25+
26+
If you need to set up completions manually, follow the instructions below. The exact
27+
config file locations might vary based on your system. Make sure to restart your
28+
shell before testing whether completions are working.
2429
25-
For example, for bash you could add this to your '~/.bash_profile':
30+
### bash
31+
32+
Add this to your %[1]s~/.bash_profile%[1]s:
2633
2734
eval "$(gh completion -s bash)"
35+
36+
### zsh
2837
29-
When installing GitHub CLI through a package manager, however, it's possible that
30-
no additional shell configuration is necessary to gain completion support. For
31-
Homebrew, see https://docs.brew.sh/Shell-Completion
32-
`),
38+
Generate a %[1]s_gh%[1]s completion script and put it somewhere in your %[1]s$fpath%[1]s:
39+
40+
gh completion -s zsh > /usr/local/share/zsh/site-functions/_gh
41+
42+
Ensure that the following is present in your %[1]s~/.zshrc%[1]s:
43+
44+
autoload -U compinit
45+
compinit -i
46+
47+
Zsh version 5.7 or later is recommended.
48+
49+
### fish
50+
51+
Generate a %[1]sgh.fish%[1]s completion script:
52+
53+
gh completion -s fish > ~/.config/fish/completions/gh.fish
54+
`, "`"),
3355
RunE: func(cmd *cobra.Command, args []string) error {
3456
if shellType == "" {
3557
if io.IsStdoutTTY() {
@@ -54,6 +76,7 @@ func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command {
5476
return fmt.Errorf("unsupported shell type %q", shellType)
5577
}
5678
},
79+
DisableFlagsInUseLine: true,
5780
}
5881

5982
cmdutil.DisableAuthCheck(cmd)

0 commit comments

Comments
 (0)