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

Support automatic zsh completions with fpath #702

Closed
andrewthauer opened this issue May 14, 2024 · 0 comments · Fixed by #703
Closed

Support automatic zsh completions with fpath #702

andrewthauer opened this issue May 14, 2024 · 0 comments · Fixed by #703

Comments

@andrewthauer
Copy link
Contributor

andrewthauer commented May 14, 2024

It would be great if you could generate completions and then add them to the zsh fpath so they are automatically loaded.

For example, installing git with homebrew will add this file /opt/homebrew/share/zsh/site-functions/_git. If the parent directory is added to the special zsh fpath variable before compinit is called the completions will work without any explicit configuration. Most popular zsh frameworks like oh-my-zsh will setup this up for you by default.

However the currently generated completions for cliffy are not compatible with this approach and have no effect. They only work if you explicitly source the generated completions.

I did some experimenting and found there are 3 main differences from other common tool completions that seem to be the problem.

  • The first line needs to be #compdef <name>
  • There needs to be a non commented _<name> "$@" call. There is a similar line at the end but commented out.
  • The usage of (($+functions[...])) || function ... seems to cause a recursion issue when applying the previous changes. Removing the functions check fixes the issue. Not sure why.

I am not sure if there was a specific reason for the way it's currently done or if changing it to the way I suggested also works when sourcing. I would be willing to g to open a PR to demonstrate the suggested changes.

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

Successfully merging a pull request may close this issue.

1 participant