-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion.go
45 lines (35 loc) · 828 Bytes
/
completion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion [shell]",
Args: cobra.OnlyValidArgs,
ValidArgs: []string{"bash", "zsh"},
Short: "Generate shell completions",
Long: `To load completion run
. <(jk completion)
To configure your bash shell to load completions for each session add to your bashrc
# ~/.bashrc or ~/.profile
. <(jk completion)
If you want to use zsh instead, do the following:
$ jk completion zsh > _jk
Then move _jk into $fpath and run compinit.
`,
Run: func(cmd *cobra.Command, args []string) {
shell := "bash"
if len(args) > 0 {
shell = args[0]
}
switch shell {
case "zsh":
jk.GenZshCompletion(os.Stdout)
default:
jk.GenBashCompletion(os.Stdout)
}
},
}
func init() {
jk.AddCommand(completionCmd)
}