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

Add a working completion example for 'zsh' shell #374

Open
anatol opened this issue Nov 1, 2021 · 1 comment
Open

Add a working completion example for 'zsh' shell #374

anatol opened this issue Nov 1, 2021 · 1 comment

Comments

@anatol
Copy link

anatol commented Nov 1, 2021

Currently documentation provides an example of completion for bash shell only.

zsh is one of the popular shells. it would be great to have completion example for this shell as well.

@drshriveer
Copy link

drshriveer commented Sep 5, 2024

#414

here ya go:

#compdef examples
compdef _examples examples

_examples() {
  local IFS=$'\n'
  local -a completions
  completions=($(GO_FLAGS_COMPLETION=1 "${words[@]}"))
  if [[ -n "$completions" ]]; then
    _describe 'command' completions
  fi
	return 1
}

# don't run the completion function when being source-ed or eval-ed
if [ "$funcstack[1]" = "_examples" ]; then
    _examples "$@"
fi

Where examples is just the name of the installed executable.

Note: This script needs to be installed in one of the $fpath directors, and needs to be loaded / inited via something like autoload -U compinit in your .zshrc. I'm a little unclear on specifics here, but if it helps this is what I have in my .zshrc:

fpath=(~/.zsh_completions $fpath)
autoload -U compinit
compinit

And I put the script in ~/.zsh_completions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants