Kylix3511
Kylix3511

Reputation: 11

Can I use Bash autocompletions for kubectl in fish?

Does anybody use fish shell with Kubectl commands? This Bash completion source <(kubectl completion bash | sed 's/kubectl/k/g') works like dizzying charm for Bash. But how to do that same thing in fish shell?

Upvotes: 1

Views: 1941

Answers (2)

DrPhil
DrPhil

Reputation: 386

In Fish this would easiest be solved with an abbreviation. Running abbr --add --global k kubectl will permanently add an abbreviation k that gets replaced with kubectl when you press space/enter. After the auto-replacement, any existing autocompletions you already have installed for kubectl will work as normal. (See the official docs for installing kubectl autocompletions if you don't have them already.)

Abbrevations in fish can replace use-cases that many other shells use aliases for, but still allow editing the command line in case you want to tweak something manually. For example, I have a fish port of the common kubectl-aliases that adds the shortcuts as abbreviations.

Upvotes: 2

faho
faho

Reputation: 15944

Fish is not generally compatible with bash, and bash's completion system is quite different from fish's. It's possible to jerry-rig some of it (if a tool takes $COMP_CWORD and such), but the real solution is to use a completion script written for fish, like https://github.com/evanlucas/fish-kubectl-completions.

There was also some work to integrate fish completions upstream, but that has seemingly stalled.

Upvotes: 2

Related Questions