Repository navigation
Generated completions that behave like ordinary plugins: null + id-as + atclone/atpull #803
olegturzhanskii
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Some tools ship zsh completions, some can generate them, and some need a file extracted out of another project.
I wanted all three to behave identically, meaning installed on first use, refreshed by
zi update, and removed when the tool goes away, without writing something of my own alongside zinit.What I ended up with is
zdharma-continuum/nullwithid-as, so a directory of generated completion files is a plugin as far as zinit is concerned.Simplified to one instance:
zinit \ as"null" \ light-mode \ lucid \ run-atpull for \ atclone' rustup completions zsh >! _rustup rustup completions zsh cargo >! _cargo zi creinstall . ' \ atpull"_update_rustup_completions" \ has"rustup" \ id-as"olegturzhanskii/rustup-completions" \ trigger-load"!rustup" \ zdharma-continuum/nullatclonegenerates at install time,atpullwithrun-atpullregenerates on update,hasskips the whole thing when the tool is absent, andtrigger-loadmeans none of it costs anything until the command is first typed.There are three instances of this in my setup: extract
_golangfromzsh-users/zsh-completions, generate for rustup, and reconcile against uv's own receipt files for anything installed withuv tool install.The Go one is cloned with
cloneonly nocompile nocompletions, because I want one file out of 190 and not the other 189 ahead of Homebrew's.Four things that cost me time, in case they save someone else some.
atloadruns on every load, not only on install.Mine ran
zi update zsh-users/zsh-completions, so the firstgoin every new shell did a network fetch, andatpullis the hook for that.Ice bodies in single quotes are evaluated later, in a different scope.
A variable that the calling file
unsets at startup is empty by the timeatcloneruns, so${ZINIT[PLUGINS_DIR]}works and your own temporaries do not.atinitandatloadrun with the plugin directory as$PWD.That matters when a hook needs its own plugin path: zinit cds in first, so DIRECTORY "$PWD" captures the plugin directory.
zinit sets its own
fpathposition, and configuration cannot override it.zinit.zshprepends${ZINIT[COMPLETIONS_DIR]}and the cache completions directory at source time, so anfpath[1,0]=(…)only reorders zinit's two directories relative to each other.I deleted mine as dead code.
The whole file, if it is useful: https://github.com/olegturzhanskii/dotfiles/blob/v0.1.0/zsh/.config/zsh/plugins.zsh
All reactions