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

How to properly init completions? #16

Closed
mike-code opened this issue Dec 13, 2023 · 3 comments
Closed

How to properly init completions? #16

mike-code opened this issue Dec 13, 2023 · 3 comments

Comments

@mike-code
Copy link

Hi.

big fan of antidote here so I wanted to give your completions a try too. I have a few questions here

  1. If I use mattmc3/zephyr path:plugins/completion, do I still need to call, the following?
autoload -Uz compinit
compinit

I'm asking this because antidote autocompletion docs suggest: "run autoload+compinit manually or use plugin". I understood it as, if I use plugin, I don't need to run compinit myself anymore. Would that be correct? nb: if I don't run compinit in my zshrc, some autocompletion won't work (like the ones from /usr/local/share/zsh/site-functions).

  1. If I use mattmc3/zephyr path:plugins/completion, I don't (shouldn't) have to use zsh-users/zsh-completions, right?
  2. If I comment out zsh-users/zsh-completions, I get odd errors like (eval):1: _nano: function definition file not found (I've deleted ~/.zcompdump just in case) -- do you an idea why could that be?
@mattmc3
Copy link
Owner

mattmc3 commented Dec 13, 2023

Hi @mike-code! Thank you for the kind words and for using antidote. Happy to answer your questions.

If I use mattmc3/zephyr path:plugins/completion, do I still need to call [compinit]

Not be default, no. This plugins calls compint for you, unless you want to do it yourself. If you prefer to run it yourself, add the following zstyle customization:

zstyle ':zephyr:plugin:completion' manual 'yes'

Then, you can call the run-compinit function that Zephyr defines for you whenever you want, or you can stick to the Zsh conventional way and run autoload -Uz compinit; compinit

I'm asking this because antidote autocompletion docs suggest: "run autoload+compinit manually or use plugin"

Zephyr provides one such plugin. You could also use belak/zsh-utils path:completion, sorin-ionescu/prezto path:modules/completion, though obviously I have some bias towards Zephyr and will ensure that it works well for antidote users.

If I use mattmc3/zephyr path:plugins/completion, I don't (shouldn't) have to use zsh-users/zsh-completions, right?

Actually, you should. Assuming there are completions defined there that you want/need. When it comes to Zsh completions, there are 3 things being handled:

  1. Build out fpath with completions, as defined in _completion files. This is what zsh-users/zsh-completions does
  2. Define how you want your completions to work. This is done by defining zstyles, and Zephyr does this.
  3. Run compinit to initialize your completions from your fpath. Zephyr also does this.

If I comment out zsh-users/zsh-completions, I get odd errors like (eval):1: _nano: function definition file not found (I've deleted ~/.zcompdump just in case) -- do you an idea why could that be?

That's usually due to your completions being cached, and _nano is defined by zsh-completions/src/_nano.

TLDR; the recommendation for your .zsh_plugins.txt file for antidote might look like this:

# ~/.zsh_plugins.txt
zsh-users/zsh-completions kind:fpath path:src
mattmc3/zephyr path:plugins/completion

@mike-code
Copy link
Author

Thanks for the detailed explanation!

Not be default, no. This plugins calls compint for you

alright, so for some reason it doesn't work for me unless I run it myself. I've stripped out all the noise in case sth was conflicting with the plugin and what I'm left with now is:

.zshrc

#!/usr/bin/env zsh

source ${ZDOTDIR:-~}/.antidote/antidote.zsh
antidote load

# autoload -Uz compinit
# compinit

.zsh_plugins.txt

zsh-users/zsh-completions kind:fpath path:src
mattmc3/zephyr path:plugins/completion

_k0s

raspi# echo $fpath[1]
/usr/local/share/zsh/site-functions

raspi# ls /usr/local/share/zsh/site-functions
_k0s

raspi# cat /usr/local/share/zsh/site-functions/_k0s | head -n 3
#compdef k0s
compdef _k0s k0s

Now if I try k0s <tab> I will see

raspi# k0s
 -- file --
[...] my files [...]

but if I uncomment autoload + compinit lines in the zshrc and restart shell, I'll see (as expected)

raspi# k0s airgap
 -- completions --
airgap      -- Manage airgap setup
[...] etc

@mattmc3
Copy link
Owner

mattmc3 commented Jul 16, 2024

I have pushed a new set of commits that I think addresses these sorts of completion questions once and for all. I have used hooks to add a new post_zshrc event. If you include Zephyr's completion plugin, it will queue up all calls to compdef for you and then it will run compinit for you at the end of your zshrc. You can also choose to run compinit yourself whenever you're ready, but Zephyr will now do it for you at the end of your config if you don't manually run it. This way, you can safely include completions at the top of your plugin list, continue to build out fpath with subsequent plugins, and be assured that your completions will pick up everything and apply any compdefs calls your plugins make. I've been testing this for about 6 months with great success, and feel it's ready for inclusion in Zephyr.

@mattmc3 mattmc3 closed this as completed Jul 16, 2024
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