kubeswitch icon indicating copy to clipboard operation
kubeswitch copied to clipboard

Add completion support for bash|zsh|fish

Open aohoyd opened this issue 1 year ago • 5 comments

Completions were rewritten to make it possible to have completions for all shells.

  • cmd/switcher/switcher.go was split into subcommands
  • new subcommand switch completion was introduced in cmd/switcher/completion.go
  • new subcommands list-contexts, delete-context, unset-context and current-context were implemented to make shell script as small as possible
  • flags -u|-d|-c were moved from shell into binary

Note: fish shell has built-in command switch so kubeswitch was used for fish

Fixes #42, fixes #46

aohoyd avatar Aug 30 '22 11:08 aohoyd

Thank you! Will take a look. Could you also resolve the merge conflicts?

danielfoehrKn avatar Aug 30 '22 21:08 danielfoehrKn

Could you also resolve the merge conflicts?

Fixed

aohoyd avatar Aug 31 '22 07:08 aohoyd

@danielfoehrKn What do you think about embedding? There will be only one binary which would produce needed shell functions to source them. Final flow be like:

source <(switcher init bash —enable-completion)  # here switcher init outputs function switch() from hack/switch/switch.sh with required completions
switch …

aohoyd avatar Aug 31 '22 16:08 aohoyd

What do you think about embedding?

I am not quite sure how that is different from your current approach . You could still use the switcher binary to generate the bash|fish|zsh completions and source them. Maybe I am misunderstanding something.

danielfoehrKn avatar Aug 31 '22 19:08 danielfoehrKn

I am not quite sure how that is different from your current approach

Now kubeswitch contains binary switcher, switch.sh script and switch.fish script. So to completely activate switch with full completions support users should execute

source switch.sh
source <(switch completion bash)

My idea is to generate internals of switch.sh script by init subcommand. So the script above would be

source <(switcher init bash)

I mean scripts switch.sh and switch.fish can be also embedded into binary. Final distribution would contain only one binary without additional scripts

aohoyd avatar Aug 31 '22 20:08 aohoyd