Skip to content

Commit

Permalink
Extend shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Sheiko committed May 19, 2021
1 parent c9569b6 commit 4e2364e
Showing 1 changed file with 49 additions and 8 deletions.
57 changes: 49 additions & 8 deletions pkg/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,61 @@ import (
// NewCmdCompletion return completion command
func NewCmdCompletion() *cobra.Command {
return &cobra.Command{
Use: "completion",
Use: "completion [bash|zsh|fish|powershell]",
DisableFlagsInUseLine: true,
Short: "Generates bash completion scripts",
Long: `To load completion run
Short: "Generate completion script",
Long: `To load completions:
. <(app2kube completion)
Bash:
To configure your bash shell to load completions for each session add to your bashrc
$ source <(app2kube completion bash)
# ~/.bashrc or ~/.profile
. <(app2kube completion)
# To load completions for each session, execute once:
# Linux:
$ app2kube completion bash > /etc/bash_completion.d/app2kube
# macOS:
$ app2kube completion bash > /usr/local/etc/bash_completion.d/app2kube
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ app2kube completion zsh > "${fpath[1]}/_app2kube"
# You will need to start a new shell for this setup to take effect.
fish:
$ app2kube completion fish | source
# To load completions for each session, execute once:
$ app2kube completion fish > ~/.config/fish/completions/app2kube.fish
PowerShell:
PS> app2kube completion powershell | Out-String | Invoke-Expression
# To load completions for every new session, run:
PS> app2kube completion powershell > app2kube.ps1
# and source this file from your PowerShell profile.
`,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(os.Stdout)
switch args[0] {
case "bash":
rootCmd.GenBashCompletion(os.Stdout)
case "zsh":
rootCmd.GenZshCompletion(os.Stdout)
case "fish":
rootCmd.GenFishCompletion(os.Stdout, true)
case "powershell":
rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
}
},
}
}

0 comments on commit 4e2364e

Please sign in to comment.