forked from mirror/cobra
Update shell_completions.md to have automatically rootcmd (#1372)
* Update shell_completions.md
This commit is contained in:
parent
6f19fa9f61
commit
d298d79e6a
|
@ -28,17 +28,17 @@ and then modifying the generated `cmd/completion.go` file to look something like
|
||||||
var completionCmd = &cobra.Command{
|
var completionCmd = &cobra.Command{
|
||||||
Use: "completion [bash|zsh|fish|powershell]",
|
Use: "completion [bash|zsh|fish|powershell]",
|
||||||
Short: "Generate completion script",
|
Short: "Generate completion script",
|
||||||
Long: `To load completions:
|
Long: fmt.Sprintf(`To load completions:
|
||||||
|
|
||||||
Bash:
|
Bash:
|
||||||
|
|
||||||
$ source <(yourprogram completion bash)
|
$ source <(%[1]s completion bash)
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# To load completions for each session, execute once:
|
||||||
# Linux:
|
# Linux:
|
||||||
$ yourprogram completion bash > /etc/bash_completion.d/yourprogram
|
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
|
||||||
# macOS:
|
# macOS:
|
||||||
$ yourprogram completion bash > /usr/local/etc/bash_completion.d/yourprogram
|
$ %[1]s completion bash > /usr/local/etc/bash_completion.d/%[1]s
|
||||||
|
|
||||||
Zsh:
|
Zsh:
|
||||||
|
|
||||||
|
@ -48,25 +48,25 @@ Zsh:
|
||||||
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# 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.
|
# You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
fish:
|
fish:
|
||||||
|
|
||||||
$ yourprogram completion fish | source
|
$ %[1]s completion fish | source
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# 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:
|
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:
|
# 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.
|
# and source this file from your PowerShell profile.
|
||||||
`,
|
`,cmd.Root().Name()),
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||||
Args: cobra.ExactValidArgs(1),
|
Args: cobra.ExactValidArgs(1),
|
||||||
|
|
Loading…
Reference in New Issue