zgen
zgen copied to clipboard
Support Zsh plugin standard?
Hello! There's attempt of mine to write down and clarify Zsh plugin standard. It follows Oh-My-Zsh unwritten standard, but solves a few issues like:
- Incompatibility with
*_argzero
options likeno_function_argzero
. - Lack of indicator that plugin is loaded by a plugin manager.
- No help from plugin manager in handling of dependencies.
- No support for plugin unloading.
- etc.
For a plugin manager, a short list of needed changes is:
- Set
ZERO
parameter at plugin load time, equal to path to sourced script ($0
from within the script). - Set
LOADED_PLUGINS
array to hold strings "user/plugin" of loaded plugins and the plugin being currently loaded. - Set
ZPFX
to a prefix-like directory (/usr
,/usr/local
,/opt
are examples of such directories). Zplug and Zplugin can do build-hooks and run Makefiles, providingZPFX
allows consistent and short hook-code. - Call
*_unload
function if it's provided, if user requests plugin unload.
Zgen architecture is about generating script with sequence of source
commands. With above commands, the script could look like:
typeset -ga LOADED_PLUGINS # typeset, in case user turns on `warn_create_global`
typeset -g ZERO ZPFX="$HOME/.zgen/polaris"
LOADED_PLUGINS+=( "geometry-zsh/geometry" )
ZERO="$HOME/.zgen/.../geometry.plugin.zsh"
fpath+=( "$HOME/.zgen/.../geometry-zsh" )
source $HOME/.zgen/.../geometry.plugin.zsh
LOADED_PLUGINS+=( "zsh-users/zsh-autosuggestions" )
ZERO="$HOME/.zgen/.../zsh-autosuggestions.plugin.zsh"
fpath+=( "$HOME/.zgen/.../zsh-autosuggestions" )
source $HOME/.zgen/.../zsh-autosuggestions.plugin.zsh
...
I've sent a patch to Zsh and it was accepted, it uses realloc()
for array appends and is faster than previous code anywhere in 10 to 1000 times, so I think there's no pain of lowering zgen's excellent performance. ZERO will release programmers' will to do tricks. So for example zgen could issue:
...
LOADED_PLUGINS+=( "geometry-zsh/geometry" )
ZERO="$HOME/.zgen/.../geometry.plugin.zsh"
fpath+=( "$HOME/.zgen/.../geometry-zsh" )
eval "$(<$HOME/.zgen/.../geometry.plugin.zsh)"
...
$ZPFX
hints that despite performance-centered architecture of Zgen, it can still do build-time (installation, update) hooks and make use of $ZPFX
(to run e.g. make PREFIX=$ZPFX install
).
Does this make sense to you? Maybe you have ideas for extensions or modifications for the standard? It is located here:
http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
PRs can be submitted here.
I've created a PR with partial implementation (the most important parts) of the standard: #124.
Hi @psprint,
I've forked zgen (see zgenom).
I'd like to support the zsh plugin standard
but I'm not really sure of the benefit of most "rules".
-
$ZERO
why not just use$0
? -
$LOADED_PLUGINS
👍 -
$ZPFX
zgenom doesn't support hooks, what is the benefit of setting ZPFX when the hooks aren't used anyways? -
*_unload
zgenom doesn't allow to unload plugins.
See https://github.com/jandamm/zgenom/issues/27