Skip to content
Myr

Include a basic example #465 (#631)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jason Hendry · committed by Eric Paris · parent ef82de7 · Browse files · 1 file+35 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+35 added−0 removed

  • other:+35 added−0 removed

1 file+35 added−0 removed

modified:bash_completions.md+35 added
1# Generating Bash Completions For Your Own cobra.Command23If you are using the generator you can create a completion command by running45```bash6cobra add completion7```89Update the help text show how to install the bash_completion Linux show here [Kubectl docs show mac options](https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion)1011Writing the shell script to stdout allows the most flexible use.1213```go14// completionCmd represents the completion command15var completionCmd = &cobra.Command{16 Use: "completion",17 Short: "Generates bash completion scripts",18 Long: `To load completion run1920. <(bitbucket completion)2122To configure your bash shell to load completions for each session add to your bashrc2324# ~/.bashrc or ~/.profile25. <(bitbucket completion)26`,27 Run: func(cmd *cobra.Command, args []string) {28 rootCmd.GenBashCompletion(os.Stdout);29 },30}31```3233**Note:** The cobra generator may include messages printed to stdout for example if the config file is loaded, this will break the auto complete script343536## Example from kubectl3738Generating bash completions from a cobra command is incredibly easy. An actual program which does so for the kubernetes kubectl binary is as follows:3940```go41package main
215 unmodified lines