evanlucas / fish-kubectl-completions

kubectl completions for fish shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support `<resource>/<id>` format

Ulexus opened this issue · comments

The current model supports a whitespace delimiter, but it the slash notation makes more sense to my fingers.

Sorry it took this long to implement, but this should work now. You can kubectl get pods/<tab> and tab completion should work. This should work for the following subcommands: get describe delete edit label explain.

It doesn't appear to work for me:

~/.c/f/fish-kubectl-completions {cycore} (master|✔) $ kubectl -n log get pod/error: the server doesn't have a resource type ""
error: the server doesn't have a resource type ""
~/.c/f/fish-kubectl-completions {cycore} (master|✔) $ kubectl -n log get svc/error: the server doesn't have a resource type ""
error: the server doesn't have a resource type ""
~/.c/f/fish-kubectl-completions {cycore} (master|✔) $ kubectl -n log describe pod/error: the server doesn't have a resource type ""
error: the server doesn't have a resource type ""
~/.c/f/fish-kubectl-completions {cycore} (master|✔) $ kubectl -n log describe pod/^C
~/.c/f/fish-kubectl-completions {cycore} (master|✔) $ git show |head -n1
commit d4f548c0281ddefbc2600c0d1159db62cc98bae5
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.0", GitCommit:"0ed33881dc4355495f623c6f22e7dd0b7632b7c0", GitTreeState:"archive", BuildDate:"2018-11-11T22:48:01Z", GoVersion:"go1.11", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.1", GitCommit:"4ed3216f3ec431b140b1d899130a69fc671678f4", GitTreeState:"clean", BuildDate:"2018-10-05T16:36:14Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}

@Ulexus Hm, that's unfortunate. What version of fish shell are you running? Also, what OS and version are you running? Thanks!

fish, version 2.7.1
Gentoo Linux, x86-64 architecture. There could be any number of support library versions.

Just a curiosity: do you need to escape the slash in the regex (such as on line 222)? I've tried adding it, but it doesn't seem to help.

and what version of kubernetes/kubectl are you running?

1.12 for both client and server

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.0", GitCommit:"0ed33881dc4355495f623c6f22e7dd0b7632b7c0", GitTreeState:"archive", BuildDate:"2018-11-11T22:48:01Z", GoVersion:"go1.11", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.1", GitCommit:"4ed3216f3ec431b140b1d899130a69fc671678f4", GitTreeState:"clean", BuildDate:"2018-10-05T16:36:14Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}

I should also mention that space-separated terms resolve just fine, with exactly the same tab completion:

$ kubectl -n log get pod oklog-0

Okay, I'm pretty sure this is fixed now. Can you try the latest commit on the master branch?

Well, it's definitely a different error (commit 0050f85):

(note that I pressed after typing kubectl get pod/sip)

~ $ kubectl get pod/sipset: Unknown option “-a”
~/.config/fish/completions/kubectl.fish (line 302): 
  set -a args get "$resource" -o name
  ^
in function “__fish_kubectl_print_resource”
	called on line 218 of file ~/.config/fish/completions/kubectl.fish
	with parameter list “”

in command substitution
	called on line 216 of file ~/.config/fish/completions/kubectl.fish

in function “__fish_kubectl_print_matching_resources”
	called on standard input

in command substitution
	called on standard input


       setset - display and change shell variables.
        -

   Synopsis
       set [SCOPE_OPTIONS]
       set [OPTIONS] VARIABLE_NAME VALUES...
       set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES...
       set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES...
       set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME
       set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]...
       set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]...

set: Type “help set” for related documentation

set: Unknown option “-a”
~/.config/fish/completions/kubectl.fish (line 302): 
  set -a args get "$resource" -o name
  ^
in function “__fish_kubectl_print_resource”
	called on line 218 of file ~/.config/fish/completions/kubectl.fish
	with parameter list “”

in command substitution
	called on line 216 of file ~/.config/fish/completions/kubectl.fish

in function “__fish_kubectl_print_matching_resources”
	called on standard input

in command substitution
	called on standard input


       setset - display and change shell variables.
        -

   Synopsis
       set [SCOPE_OPTIONS]
       set [OPTIONS] VARIABLE_NAME VALUES...
       set [OPTIONS] VARIABLE_NAME[INDICES]... VALUES...
       set ( -q | --query ) [SCOPE_OPTIONS] VARIABLE_NAMES...
       set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME
       set ( -e | --erase ) [SCOPE_OPTIONS] VARIABLE_NAME[INDICES]...
       set ( -S | --show ) [SCOPE_OPTIONS] [VARIABLE_NAME]...

set: Type “help set” for related documentation

ahhhh, looks like set -a is only available in fish shell 3.0.0+. Lemme see if I can make it backwards compatible. Sorry about that

Alright, just pushed what should make this work on fish 2.x and 3.x. Can you give latest master branch a try? Btw, thanks a ton for all of the feedback. I really appreciate you helping make this better!

Aha; I didn't realize I had missed a (major!) fish release.

With fish 2.7.1, it goes back to the old behaviour: error: the server doesn't have a resource type ""

With fish 3.0.0, however, it works! Thanks!

I am perfectly happy with this feature just requiring the current version of fish.