Skip to content

Commit 66a7cf2

Browse files
committed
Add fish auto completion
1 parent a8c9e7a commit 66a7cf2

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

Diff for: cmd/minikube/cmd/completion.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
const longDescription = `
31-
Outputs minikube shell completion for the given shell (bash or zsh)
31+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
3232
3333
This depends on the bash-completion binary. Example installation instructions:
3434
OS X:
@@ -37,15 +37,18 @@ const longDescription = `
3737
$ minikube completion bash > ~/.minikube-completion # for bash users
3838
$ minikube completion zsh > ~/.minikube-completion # for zsh users
3939
$ source ~/.minikube-completion
40+
$ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users
4041
Ubuntu:
4142
$ apt-get install bash-completion
4243
$ source /etc/bash-completion
4344
$ source <(minikube completion bash) # for bash users
4445
$ source <(minikube completion zsh) # for zsh users
46+
$ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users
4547
4648
Additionally, you may want to output the completion to a file and source in your .bashrc
4749
4850
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
51+
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion
4952
`
5053

5154
const boilerPlate = `
@@ -66,24 +69,29 @@ const boilerPlate = `
6669

6770
var completionCmd = &cobra.Command{
6871
Use: "completion SHELL",
69-
Short: "Outputs minikube shell completion for the given shell (bash or zsh)",
72+
Short: "Outputs minikube shell completion for the given shell (bash, zsh or fish)",
7073
Long: longDescription,
7174
Run: func(cmd *cobra.Command, args []string) {
7275
if len(args) != 1 {
7376
exit.UsageT("Usage: minikube completion SHELL")
7477
}
75-
if args[0] != "bash" && args[0] != "zsh" {
78+
if args[0] != "bash" && args[0] != "zsh" && args[0] != "fish" {
7679
exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]})
7780
} else if args[0] == "bash" {
7881
err := GenerateBashCompletion(os.Stdout, cmd.Parent())
7982
if err != nil {
8083
exit.WithError("bash completion failed", err)
8184
}
82-
} else {
85+
} else if args[0] == "zsh" {
8386
err := GenerateZshCompletion(os.Stdout, cmd.Parent())
8487
if err != nil {
8588
exit.WithError("zsh completion failed", err)
8689
}
90+
} else {
91+
err := GenerateFishCompletion(os.Stdout, cmd.Parent())
92+
if err != nil {
93+
exit.WithError("fish completion failed", err)
94+
}
8795
}
8896

8997
},
@@ -279,3 +287,18 @@ __minikube_bash_source <(__minikube_convert_bash_to_zsh)
279287

280288
return nil
281289
}
290+
291+
// GenerateBashCompletion generates the completion for the bash shell
292+
func GenerateFishCompletion(w io.Writer, cmd *cobra.Command) error {
293+
_, err := w.Write([]byte(boilerPlate))
294+
if err != nil {
295+
return err
296+
}
297+
298+
err = cmd.GenFishCompletion(w, true)
299+
if err != nil {
300+
return errors.Wrap(err, "Error generating fish completion")
301+
}
302+
303+
return nil
304+
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ require (
7070
github.com/samalba/dockerclient v0.0.0-20160414174713-91d7393ff859 // indirect
7171
github.com/shirou/gopsutil v2.18.12+incompatible
7272
github.com/spf13/cast v1.3.1 // indirect
73-
github.com/spf13/cobra v0.0.5
73+
github.com/spf13/cobra v1.0.0
7474
github.com/spf13/pflag v1.0.5
7575
github.com/spf13/viper v1.6.1
7676
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect

Diff for: go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfc
156156
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
157157
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
158158
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
159+
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
160+
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
159161
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
160162
github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg=
161163
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
@@ -706,6 +708,8 @@ github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNue
706708
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
707709
github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 h1:tlXG832s5pa9x9Gs3Rp2rTvEqjiDEuETUOSfBEiTcns=
708710
github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
711+
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
712+
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
709713
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
710714
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
711715
github.com/sayboras/dockerclient v0.0.0-20191231050035-015626177a97 h1:DWY4yZN6w+FSKMeqBBXaalT8zmCn4DVwBGopShnlwFE=
@@ -722,6 +726,8 @@ github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+D
722726
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
723727
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
724728
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
729+
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
730+
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
725731
github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
726732
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
727733
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
@@ -750,6 +756,8 @@ github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
750756
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
751757
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
752758
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
759+
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
760+
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
753761
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
754762
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
755763
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
@@ -764,6 +772,7 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
764772
github.com/spf13/viper v1.0.2/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
765773
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
766774
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
775+
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
767776
github.com/spf13/viper v1.6.1 h1:VPZzIkznI1YhVMRi6vNFLHSwhnhReBfgTxIPccpfdZk=
768777
github.com/spf13/viper v1.6.1/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k=
769778
github.com/storageos/go-api v0.0.0-20180912212459-343b3eff91fc/go.mod h1:ZrLn+e0ZuF3Y65PNF6dIwbJPZqfmtCXxFm9ckv0agOY=

Diff for: site/content/en/docs/commands/completion.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
title: "completion"
33
description: >
4-
Outputs minikube shell completion for the given shell (bash or zsh)
4+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
55
---
66

77

88

99
## minikube completion
1010

11-
Outputs minikube shell completion for the given shell (bash or zsh)
11+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
1212

1313
### Synopsis
1414

1515

16-
Outputs minikube shell completion for the given shell (bash or zsh)
16+
Outputs minikube shell completion for the given shell (bash, zsh or fish)
1717

1818
This depends on the bash-completion binary. Example installation instructions:
1919
OS X:
@@ -22,15 +22,18 @@ Outputs minikube shell completion for the given shell (bash or zsh)
2222
$ minikube completion bash > ~/.minikube-completion # for bash users
2323
$ minikube completion zsh > ~/.minikube-completion # for zsh users
2424
$ source ~/.minikube-completion
25+
$ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users
2526
Ubuntu:
2627
$ apt-get install bash-completion
2728
$ source /etc/bash-completion
2829
$ source <(minikube completion bash) # for bash users
2930
$ source <(minikube completion zsh) # for zsh users
31+
$ minikube completion fish > ~/.config/fish/completions/minikube.fish # for fish users
3032

3133
Additionally, you may want to output the completion to a file and source in your .bashrc
3234

3335
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2
36+
Note for fish users: [2] please refer to this docs for more details https://fishshell.com/docs/current/#tab-completion
3437

3538

3639
```

0 commit comments

Comments
 (0)