Skip to content

Commit

Permalink
Merge pull request #327 from ozzieba/bash_completion
Browse files Browse the repository at this point in the history
Add shell completion
  • Loading branch information
errordeveloper authored Dec 4, 2018
2 parents 0a87749 + a0363f3 commit a73f05f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,31 @@ eksctl apply --cluster-config advanced-cluster.yaml
```
-->

### Shell Completion

To enable bash completion, run the following, or put it in `~/.bashrc` or `~/.profile`:
```
. <(eksctl completion bash)
```

Or for zsh, run:
```
mkdir -p ~/.zsh/completion/
eksctl completion zsh > ~/.zsh/completion/_eksctl
```
and put the following in `~/.zshrc`:
```
fpath=($fpath ~/.zsh/completion)
```
Note if you're not running a distribution like oh-my-zsh you may first have to enable autocompletion:
```
autoload -U compinit
compinit
```

To make the above persistent, run the first two lines, and put the


## Project Roadmap

### Developer use-case (0.2.0)
Expand Down
2 changes: 2 additions & 0 deletions cmd/eksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/ctl/completion"
"github.com/weaveworks/eksctl/pkg/ctl/create"
"github.com/weaveworks/eksctl/pkg/ctl/delete"
"github.com/weaveworks/eksctl/pkg/ctl/get"
Expand Down Expand Up @@ -45,4 +46,5 @@ func addCommands() {
rootCmd.AddCommand(get.Command())
rootCmd.AddCommand(scale.Command())
rootCmd.AddCommand(utils.Command())
rootCmd.AddCommand(completion.Command(rootCmd))
}
61 changes: 61 additions & 0 deletions pkg/ctl/completion/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package completion

import (
"os"

"github.com/kubicorn/kubicorn/pkg/logger"

"github.com/spf13/cobra"
)

// Command will create the `completion` commands
func Command(rootCmd *cobra.Command) *cobra.Command {
var bashCompletionCmd = &cobra.Command{
Use: "bash",
Short: "Generates bash completion scripts",
Long: `To load completion run
. <(eksctl completion bash)
To configure your bash shell to load completions for each session add to your bashrc
# ~/.bashrc or ~/.profile
. <(eksctl completion bash)
`,
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenBashCompletion(os.Stdout)
},
}
var zshCompletionCmd = &cobra.Command{
Use: "zsh",
Short: "Generates zsh completion scripts",
Long: `To configure your zsh shell, run:
mkdir -p ~/.zsh/completion/
eksctl completion zsh > ~/.zsh/completion/_eksctl
and put the following in ~/.zshrc:
fpath=($fpath ~/.zsh/completion)
`,
Run: func(cmd *cobra.Command, args []string) {
rootCmd.GenZshCompletion(os.Stdout)
},
}

cmd := &cobra.Command{
Use: "completion",
Short: "Generates shell completion scripts",
Run: func(c *cobra.Command, _ []string) {
if err := c.Help(); err != nil {
logger.Debug("ignoring error %q", err.Error())
}
},
}

cmd.AddCommand(bashCompletionCmd)
cmd.AddCommand(zshCompletionCmd)

return cmd
}

0 comments on commit a73f05f

Please sign in to comment.