Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh completions can't be sourced #522

Closed
mikewl opened this issue May 13, 2019 · 12 comments
Closed

zsh completions can't be sourced #522

mikewl opened this issue May 13, 2019 · 12 comments
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@mikewl
Copy link

mikewl commented May 13, 2019

What happened:
Running source <(kind completion zsh) fails with the following error

_arguments:comparguments:325: can only be called from completion function
_arguments:comparguments:325: can only be called from completion function

What you expected to happen:
The completions to import and be available

How to reproduce it (as minimally and precisely as possible):
Run source <(kind completion zsh) in zsh

Anything else we need to know?:

Environment:

  • zsh version: zsh 5.7.1 (x86_64-apple-darwin18.2.0)
  • kind version: (use kind version): 0.3.0-alpha
  • Kubernetes version: (use kubectl version): 1.14
  • Docker version: (use docker info): 18.09.2
  • OS (e.g. from /etc/os-release): MacOS 10.14
@mikewl mikewl added the kind/bug Categorizes issue or PR as related to a bug. label May 13, 2019
@BenTheElder
Copy link
Member

hmm, I wonder if this is a bug upstream in cobra, we are generating these with that library
https://github.com/spf13/cobra

@BenTheElder
Copy link
Member

/help

@k8s-ci-robot
Copy link
Contributor

@BenTheElder:
This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label May 13, 2019
@nirnanaaa
Copy link

Might be related to spf13/cobra#646

@rsteube
Copy link

rsteube commented May 28, 2019

Did this work before? As afaik you don't source completions (as in bash) but instead add the folders containing them to fpath: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#telling-zsh-which-function-to-use-for-completing-a-command

e.g:
kind completion zsh > /somedir/_kind (once to generate it)
and in .zshrc

fpath=(/somedir $fpath)`
# and something like this (normally done by plugin managers - ideally only once for performance)
autoload -Uz compinit && \
   compinit -C

@epk
Copy link
Contributor

epk commented Jun 17, 2019

👋

I added the autocompletion subcommand.

If you run kind completion

Outputs kind shell completion for the given shell (bash or zsh)
This depends on the bash-completion binary.  Example installation instructions:
# for bash users
   $ kind completion bash > ~/.kind-completion
   $ source ~/.kind-completion
# for zsh users
   % kind completion zsh > /usr/local/share/zsh/site-functions/_kind
   % autoload -U compinit && compinit
Additionally, you may want to output the completion to a file and source in your .bashrc
Note for zsh users: [1] zsh completions are only supported in versions of zsh >= 5.2

There's a PR in spf13/cobra spf13/cobra#887 which lets you source autocompletion in zsh directly like bash but that hasn't been merged yet

@BenTheElder
Copy link
Member

BenTheElder commented Jun 17, 2019

Thanks @epk ! :-)

@BenTheElder
Copy link
Member

/assign

@BenTheElder
Copy link
Member

The upstream PR was closed.
I'm not a zsh user, but it looks like you should be using the instructions in kind completion rather than doing a source <(kind completion zsh).

ref: https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org#telling-zsh-which-function-to-use-for-completing-a-command

@BenTheElder
Copy link
Member

IMO it looks like we should probably encourage installing the completion script output instead, which kind completion currently does.

@itay-grudev
Copy link

itay-grudev commented Jun 26, 2023

I think the confusion comes from the fact that kind completion outputs the important information in the beginning (which on small terminal screens is off-screen) and general help and usage at the end, which tricks users into thinking it just expects a parameter like kind completion zsh.

image

If you do that you miss the lovely note in the beginning with detailed explanation.

Outputs kind shell completion for the given shell (bash or zsh)
This depends on the bash-completion binary.  Example installation instructions:
# for bash users
	$ kind completion bash > ~/.kind-completion
	$ source ~/.kind-completion

# for zsh users
	% kind completion zsh > /usr/local/share/zsh/site-functions/_kind
	% autoload -U compinit && compinit
# or if zsh-completion is installed via homebrew
    % kind completion zsh > "${fpath[1]}/_kind"
# or if you use oh-my-zsh (needs zsh-completions plugin)
	% mkdir $ZSH/completions/
	% kind completion zsh > $ZSH/completions/_kind

# for fish users
	% kind completion fish > ~/.config/fish/completions/kind.fish

I think if he order is swapped it'd be nicer:

  1. Usage information first
  2. Then the tutorial with examples for different shells
  3. And finally the ERROR: Subcommand is required message at the end.

@stmcginnis
Copy link
Contributor

That output comes from cobra. You may want to provide usability suggestions there: https://github.com/spf13/cobra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

8 participants