Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

feat: add fish shell completions to README #52

Merged
merged 7 commits into from Mar 11, 2021
Merged

Conversation

awinecki
Copy link
Contributor

Hello; such a great project! I'm just learning k8s, and I like my CLI UI to be clean and readable.

As I've been using fish for a while now, I was sad to discover I can't use kubecolor with proper completions with fish. Completions are necessary to me for learning, so I tried to make it work.

As I'm no expert when it comes to hacking fish, I just took @evanlucas (thx ! 馃檹 ) completions, and replaced all kubectl with kubecolor. It's ugly, but it works.

@evanlucas, perhaps you could guide me how to do it in a cleaner way. I know little about go, and seems you're using it to generate these completions. Worst case, I could just set up a github action that periodically fetches your kubectl completions and builds kubecolor ones from that.

Add a short entry to README about how to install completions for `fish` shell.

It's a hack for now (based on https://github.com/evanlucas/fish-kubectl-completions), but it works
@hidetatz
Copy link
Owner

@awinecki
Hi, thank you for sending the PR! This PR is very useful for fish users.

As I'm very new to fish, I did some testing on my side to make sure this is working, and I found another way to achieve it which look possibly simpler.

I added below function in config.fish:

function kubectl
  kubecolor $argv
end

Then, I just run kubectl then tab completion seems working, and the result is colored by kubecolor. What do you think of this?
If this works on your environment as well and this way looks sufficient to achieve the completion, I would prefer this way because it looks it requires less effort for users. If you agree with it, I want you to change this PR to describe the way instead of current one.

@awinecki
Copy link
Contributor Author

@dty1er that's actually brilliant, haven't thought of it :). Works on my machine.

I've changed the PR to guide fish users using your method. I think it's a good default.

I've also included a hint for people that would like to have both kubectl and kubecolor commands on their systems. Personally, I've noticed kubecolor adds a minor overhead (~20-30ms) to the output generation. But I guess with remote clusters this makes little difference.

nj-screenshot 2021-02-25 at 15 42 08@2x

README.md Outdated
@@ -129,7 +129,23 @@ compdef kubecolor=kubectl

#### fish

Fish completion is unsupported because fish completion is officially not supported by kubectl.
For fish, you can achieve completions for `kubecolor` in two steps:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this sentence?
I want to emphasize that this is unofficial hack because it is not official way provided by kubernetes project.

Suggested change
For fish, you can achieve completions for `kubecolor` in two steps:
Fish completion is officially unsupported by kubectl, so it is unsupported by kubecolor as well.
However, there are 2 ways we can introduce to make completion work.
Please keep in mind these ways are a kind of "hack" and not officially supported.
1. Use "fish-kubectl-completions" with kubecolor
[evanlucas/fish-kubectl-completions](https://github.com/evanlucas/fish-kubectl-completions) is popular for fish users who wants kubectl completions in fish shell.
You can "override" kubectl with kubecolor and make it work even with kubecolor. You need to follow below 2 steps:

README.md Outdated
Comment on lines 134 to 146
1. Install `kubectl` completions (https://github.com/evanlucas/fish-kubectl-completions)

```shell
fisher install evanlucas/fish-kubectl-completions
```

2. Add the following function to your `config.fish` file:

```shell
function kubectl
kubecolor $argv
end
```
Copy link
Owner

@hidetatz hidetatz Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add indents(2 spaces) to these 2 steps because they belong to above 1. Use "fish-kubectl-completions" with kubecolor

README.md Outdated
end
```

**NOTE:** This will override `kubectl` command. If you wish to preserve both `kubectl` and `kubecolor` with completions, you need to copy completions for `kubecolor` command (e.g. https://github.com/awinecki/fish-kubecolor-completions).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure some people will prefer fish-kubecolor-completions, so let's add some description:

Suggested change
**NOTE:** This will override `kubectl` command. If you wish to preserve both `kubectl` and `kubecolor` with completions, you need to copy completions for `kubecolor` command (e.g. https://github.com/awinecki/fish-kubecolor-completions).
2. Use awinecki/fish-kubecolor-completions
The first way will override `kubectl` command. If you wish to preserve both `kubectl` and `kubecolor` with completions, you need to copy evanlucas/fish-kubectl-completionsfor for `kubecolor` command.
For this purpose, you can use [awinecki/fish-kubecolor-completions](https://github.com/awinecki/fish-kubecolor-completions).

@hidetatz
Copy link
Owner

hidetatz commented Mar 3, 2021

@awinecki
Sorry to be late!
It looks pretty cool and I'm ready to press the merge button after some cosmetic changes.

@awinecki
Copy link
Contributor Author

awinecki commented Mar 4, 2021

@dty1er no problem ;) I've applied most of your suggestions, added some .md formatting for links etc.

馃檶

@hidetatz
Copy link
Owner

hidetatz commented Mar 5, 2021

image

I am sorry but my suggestion doesn't look well (there are three step2 which looks confusing)
Can you fix it accordingly?

@awinecki
Copy link
Contributor Author

@dty1er sorry for that, I've previewed it in Typora, which renders lists differently. Lesson learned.

I've fixed the formatting:

screen-2021-03-10@10 57 18

@hidetatz
Copy link
Owner

Cool, thanks a lot for your great contribution.

@hidetatz hidetatz merged commit 8da5e16 into hidetatz:main Mar 11, 2021
@awinecki awinecki deleted the patch-2 branch March 18, 2021 00:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants