zephyr
zephyr copied to clipboard
How to properly init completions?
Hi.
big fan of antidote here so I wanted to give your completions a try too. I have a few questions here
- 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).
- If I use
mattmc3/zephyr path:plugins/completion, I don't (shouldn't) have to usezsh-users/zsh-completions, right? - If I comment out
zsh-users/zsh-completions, I get odd errors like(eval):1: _nano: function definition file not found(I've deleted~/.zcompdumpjust in case) -- do you an idea why could that be?
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:
- Build out
fpathwith completions, as defined in_completionfiles. This is whatzsh-users/zsh-completionsdoes - Define how you want your completions to work. This is done by defining
zstyles, and Zephyr does this. - 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
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
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.