tarjoilija / zgen

A lightweight and simple plugin manager for ZSH
BSD 2-Clause "Simplified" License
1.49k stars 98 forks source link

Support Zsh plugin standard? #104

Open psprint opened 6 years ago

psprint commented 6 years ago

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:

  1. Incompatibility with *_argzero options like no_function_argzero.
  2. Lack of indicator that plugin is loaded by a plugin manager.
  3. No help from plugin manager in handling of dependencies.
  4. No support for plugin unloading.
  5. etc.

For a plugin manager, a short list of needed changes is:

  1. Set ZERO parameter at plugin load time, equal to path to sourced script ($0 from within the script).
  2. Set LOADED_PLUGINS array to hold strings "user/plugin" of loaded plugins and the plugin being currently loaded.
  3. 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, providing ZPFX allows consistent and short hook-code.
  4. 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.

psprint commented 4 years ago

I've created a PR with partial implementation (the most important parts) of the standard: #124.

jandamm commented 3 years ago

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".

See https://github.com/jandamm/zgenom/issues/27