Kubectl: Please add fish tab completion

Created on 19 Jan 2019  路  25Comments  路  Source: kubernetes/kubectl

Fish Completion - Feature Request

Please implement tab completion for the fish shell by building on work done in https://github.com/spf13/cobra/pull/754 or consider shipping automatically generated manpages beforehand.

Unfortunately an earlier feature request (#131) was closed even though the issue had not been addressed. Previous attempts to add completion failed due to the inability to generate them programmatically, but with the changes to cobra referenced above fixing this should be relatively straightforward.

Fish users will appreciate your efforts. Thanks!

Kubernetes version

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:35:51Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}

Related Issues

arekubectl kinfeature prioritbacklog sicli

Most helpful comment

That probably won't help too much since Kubernetes uses Cobra 0.0.5 and it might be a hard sell to to upgrade unless there are already plans to do so.

Helm just moved from Cobra 0.0.5 to 1.0: https://github.com/helm/helm/pull/7904

From my evaluation the changes are minor and backwards-compatible. But I can understand that upgrading may not happen overnight for kubectl.

It might serve as an example, but even if you look at kubectl's zsh completion works, if I recall it does not use Cobra's zsh completion, but instead translates bash completion using a series of seds to make it work for zsh.

Maybe using zsh as an example, something similar could be done for fish.

Zsh pretty much has the same scripting syntax as bash and has bash-completion compatibility support. Fish has nothing of the sort however with a scripting syntax incompatible with bash.

I think moving to Cobra 1.0 will be far less effort than developing anything specific to kubectl for fish completion.

All 25 comments

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Cobra 1.0 provides support for Fish completion: https://github.com/spf13/cobra/blob/v1.0.0/fish_completions.md

That probably won't help too much since Kubernetes uses Cobra 0.0.5 and it might be a hard sell to to upgrade unless there are already plans to do so.

It might serve as an example, but even if you look at kubectl's zsh completion works, if I recall it does not use Cobra's zsh completion, but instead translates bash completion using a series of seds to make it work for zsh.

Maybe using zsh as an example, something similar could be done for fish.

I don't know much about fish, but if someone wants to work on it, the code would go here:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/completion/completion.go

var (
    completionShells = map[string]func(out io.Writer, boilerPlate string, cmd *cobra.Command) error{
        "bash": runCompletionBash,
        "zsh":  runCompletionZsh,
                // TODO: add fish here
    }
)

/sig cli
/area kubectl
/kind feature

That probably won't help too much since Kubernetes uses Cobra 0.0.5 and it might be a hard sell to to upgrade unless there are already plans to do so.

Helm just moved from Cobra 0.0.5 to 1.0: https://github.com/helm/helm/pull/7904

From my evaluation the changes are minor and backwards-compatible. But I can understand that upgrading may not happen overnight for kubectl.

It might serve as an example, but even if you look at kubectl's zsh completion works, if I recall it does not use Cobra's zsh completion, but instead translates bash completion using a series of seds to make it work for zsh.

Maybe using zsh as an example, something similar could be done for fish.

Zsh pretty much has the same scripting syntax as bash and has bash-completion compatibility support. Fish has nothing of the sort however with a scripting syntax incompatible with bash.

I think moving to Cobra 1.0 will be far less effort than developing anything specific to kubectl for fish completion.

I'll see if I can upgrade the completion to use all shells supported by cobra 1.0.0...
Fish, PowerShell, and change Zsh to use cobra's implementation

/assign

I'll see if I can upgrade the completion to use all shells supported by cobra 1.0.0...
Fish, PowerShell,

Nice!
Be aware that Fish completion will not provide kubectl's custom completions. For that to work, kubectl must move from custom completions written in bash code to custom completions written in Go, as introduced in Cobra 1.0 (the new command.ValidArgsFunction field and the one for flags).

Also PowerShell completions do not support custom completions of any form at this time.

and change Zsh to use cobra's implementation

Don't do that yet. Cobra 1.0's support for zsh has less functionality than kubectl's current one. For example, again, no support for custom completion.

https://github.com/spf13/cobra/pull/1070 brings Zsh completion to the level of bash completions, but will only work with custom completions written in Go. So, until custom completions are modified in kubectl (and the mentioned PR is released), it is better to stay with the current solution for zsh completion.

@marckhouzam thanks for the heads up. After my last comment I also saw that cobra has a new way to implement dynamic completion, and the old way only works for bash (and zsh in our case since it just modifies bash completion).

As part of this, I'll see what it would take to move to the new dynamic completion approach. At first glance it seems like it would be an improvement.

Regarding zsh completion, I totally agree now that I looked more into it.

I know how long it took to get zsh completion where it is today, so I definitely don't want to do anything to make it worse, so yeah, I'll probably keep zsh they way is and just focus on getting fish working for now.

@brianpursley if you manage to get rid of the old dynamic completion code to use the new way, not only will it remove bash code that's difficult to maintain and test, but you'll improve fish completion automatically, and eventually you'll be able to move to native zsh completion which provide completion descriptions, which are currently not supported in kubectl's zsh solution.

So I fully agree that such an effort would provide value. Thanks!

/priority backlog

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

For full fish shell completion support, we need to move to go custom completions, which is done in https://github.com/kubernetes/kubernetes/pull/96087. Hopefully that PR can get merged eventually.

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale

Merging https://github.com/kubernetes/kubernetes/pull/96087 is slowly going forward...

/remove-lifecycle stale

Was this page helpful?
0 / 5 - 0 ratings

Related issues

J-Siu picture J-Siu  路  4Comments

fiksn picture fiksn  路  3Comments

cbluth picture cbluth  路  6Comments

drpaneas picture drpaneas  路  3Comments

ZhilinS picture ZhilinS  路  5Comments