Update shell_completions.md to have automatically rootcmd (#1372)

* Update shell_completions.md
This commit is contained in:
Ron Green 2021-12-08 00:46:48 +02:00 committed by GitHub
parent 6f19fa9f61
commit d298d79e6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,17 +28,17 @@ and then modifying the generated `cmd/completion.go` file to look something like
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
Long: `To load completions:
Long: fmt.Sprintf(`To load completions:
Bash:
$ source <(yourprogram completion bash)
$ source <(%[1]s completion bash)
# To load completions for each session, execute once:
# Linux:
$ yourprogram completion bash > /etc/bash_completion.d/yourprogram
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
# macOS:
$ yourprogram completion bash > /usr/local/etc/bash_completion.d/yourprogram
$ %[1]s completion bash > /usr/local/etc/bash_completion.d/%[1]s
Zsh:
@ -48,25 +48,25 @@ Zsh:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ yourprogram completion zsh > "${fpath[1]}/_yourprogram"
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
# You will need to start a new shell for this setup to take effect.
fish:
$ yourprogram completion fish | source
$ %[1]s completion fish | source
# To load completions for each session, execute once:
$ yourprogram completion fish > ~/.config/fish/completions/yourprogram.fish
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
PowerShell:
PS> yourprogram completion powershell | Out-String | Invoke-Expression
PS> %[1]s completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> yourprogram completion powershell > yourprogram.ps1
PS> %[1]s completion powershell > %[1]s.ps1
# and source this file from your PowerShell profile.
`,
`,cmd.Root().Name()),
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),