# zgenom A lightweight yet powerful plugin manager for Zsh. It is a superset of the brilliant [zgen](https://github.com/tarjoilija/zgen). Providing more features and bugfixes while being fully backwards compatible. Have a look at the [migration guide](#migration-from-zgen) if you're currently using `zgen`. Also have a look at [new features](#new-features) of zgenom. Zgenom provides you simple commands for managing plugins. It installs your plugins and generates a static init script that will source them for you every time you run the shell. We do this to save some startup time by not having to execute time consuming logic (plugin checking, updates, etc) every time a new shell session is started. This means that you have to manually check for updates (`zgenom update`) and reset the init script (`zgenom reset`) whenever you add or remove plugins. Zgenom does have a `zgenom autoupdate` which checks for updates periodically without startup penalty or having to wait for the plugins to update. See [here](#run-updates-automatically) for more information. ## Installation
... Clone the zgenom repository: ```zsh git clone https://github.com/jandamm/zgenom.git "${HOME}/.zgenom" ``` Edit your .zshrc file to load zgenom: ```zsh # load zgenom source "${HOME}/.zgenom/zgenom.zsh" ``` Place the following code after the one above to load ohmyzsh for example, see [Example](#example-zshrc) and [Usage](#usage) for more details. ```zsh # if the init script doesn't exist if ! zgenom saved; then # specify plugins here zgenom ohmyzsh # generate the init script from plugins above zgenom save fi ``` If you're currently using zgen [see below](#migration-from-zgen).
## Example .zshrc ```zsh # load zgenom source "${HOME}/.zgenom/zgenom.zsh" # Check for plugin and zgenom updates every 7 days # This does not increase the startup time. zgenom autoupdate # if the init script doesn't exist if ! zgenom saved; then echo "Creating a zgenom save" # Add this if you experience issues with missing completions or errors mentioning compdef. # zgenom compdef # Ohmyzsh base library zgenom ohmyzsh # You can also cherry pick just parts of the base library. # Not loading the base set of ohmyzsh libraries might lead to issues. # While you can do it, I won't recommend it unless you know how to fix # those issues yourself. # Remove `zgenom ohmyzsh` and load parts of ohmyzsh like this: # `zgenom ohmyzsh path/to/file.zsh` # zgenom ohmyzsh lib/git.zsh # load git library of ohmyzsh # plugins zgenom ohmyzsh plugins/git zgenom ohmyzsh plugins/sudo # just load the completions zgenom ohmyzsh --completion plugins/docker-compose # Install ohmyzsh osx plugin if on macOS [[ "$(uname -s)" = Darwin ]] && zgenom ohmyzsh plugins/macos # prezto options zgenom prezto editor key-bindings 'emacs' zgenom prezto prompt theme 'sorin' # prezto and modules # If you use prezto and ohmyzsh - load ohmyzsh first. zgenom prezto zgenom prezto command-not-found # Load prezto tmux when tmux is installed if hash tmux &>/dev/null; then zgenom prezto tmux fi zgenom load zsh-users/zsh-syntax-highlighting zgenom load /path/to/super-secret-private-plugin # use a plugin file # The file must only contain valid parameters for `zgenom load` zgenom loadall < path/to/plugin/file # bulk load zgenom loadall < --no-submodules`. - Full support for non `master` branches (e.g. `main`). This includes following a new default branch. - compinit with custom flags wasn't working properly. - Update to `ohmyzsh/ohmyzsh`. - Implement the [Zsh Plugin Standard](#zsh-plugin-standard). - Add `zgenom clean` to remove all unused plugins. - Add `zgenom autoupdate` to check for updates periodically and dispatch it to the background to remove any waiting times. - Allow just adding a plugins directory to fpath using `--completion` with `load` or `ohmyzsh`. - Add `zgenom compdef` to add `compdef` before loading plugins. ## Usage
... ### ohmyzsh This is a handy shortcut for installing ohmyzsh plugins. They can be loaded using `zgenom load` too with a significantly longer format. #### Load ohmyzsh base It's a good idea to load the base components before specifying any plugins. ```zsh zgenom ohmyzsh ``` #### Load ohmyzsh plugins ```zsh zgenom ohmyzsh ``` #### Example ```zsh zgenom ohmyzsh zgenom ohmyzsh plugins/git zgenom ohmyzsh plugins/sudo zgenom ohmyzsh plugins/command-not-found # Just use the completions in this directory zgenom ohmyzsh --completion plugins/docker-compose zgenom ohmyzsh themes/arrow ``` ### Prezto #### Load Prezto ```zsh zgenom prezto ``` This will create a symlink in the `$ZSHDOTDIR` or `$HOME` directory. This is needed by prezto. **Note:** When `zgenom prezto` is used with `zgenom ohmyzsh` together, `prezto` should be **put behind** `ohmyzsh`. Or prompt theme from prezto may not display as expected. #### Load prezto plugins ```zsh zgenom prezto ``` This uses the Prezto method for loading modules. **Note:** Some modules from prezto are enabled by default. Use `ZGEN_PREZTO_LOAD_DEFAULT=0` to disable this behavior. #### Load a repo as Prezto plugins ```zsh zgenom pmodule ``` This uses the Prezto method for loading the module. It creates a symlink and calls `pmodule`. #### Set prezto options ```zsh zgenom prezto
## Notes While this README uses `zgenom` and `ohmyzsh` the old versions `zgen` and `oh-my-zsh` can be used interchangeably. Environment variables are still prefixed with `ZGEN_` to keep backwards compatibility. When `zgenom` introduces new variables they are prefixed with `ZGENOM_`. Be aware that `zgenom` tries to handle [`compinit`][compinit] for you to allow for the fastest possible initialization times. However, this functionality will be disabled if you've already called `compinit` yourself before sourcing `zgenom.zsh`. Alternatively, you can disable it yourself by disabling `$ZGEN_AUTOLOAD_COMPINIT`. [compinit]: "Zsh manual 20.2.1: Use of compinit" ## Extensions Extensions may be a bit of a stretch. Every function matching `zgenom-*` is callable like `zgenom *`. Every completion function matching `_zgenom_*` is called by `_zgenom`. Also `$ZGENOM_EXTENSIONS` can be used to add an entry to `zgenom help` and subcommand completion. To provide an extension called `abc` you define `zgenom-abc` in your plugin. Then you can add a description: `ZGENOM_EXTENSIONS+=('abc:Some description')`. To provide additional completions you can define `_zgenom_abc` which will be called when the prompt starts with `zgenom abc`. Existing extensions: - [eval](https://github.com/jandamm/zgenom-ext-eval): Use `zgenom` to quickly generate plugins from a command or heredoc. - [release](https://github.com/jandamm/zgenom-ext-release): Use `zgenom` and `gh` to download github releases. - [run](https://github.com/jandamm/zgenom-ext-run): Use `zgenom` to run commands in the plugin folder (e.g. `make`). Please create a PR to add your extension here :) **Note:** It is not recommended to use the private api (`__zgenom-*`) since it may change without further notice. Use `zgenom api` instead. ## Other resources The [awesome-zsh-plugins](https://github.com/unixorn/awesome-zsh-plugins) list contains many zgenom compatible zsh plugins & themes that you may find useful. There's a [zsh-quickstart-kit](https://github.com/unixorn/zsh-quickstart-kit) for using zsh and zgenom that does a guided setup of zgenom, including installing a starting sampler of useful plugins. ### [Zsh Plugin Standard](https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html) The Zsh Plugin Standard describes how a plugin for zsh should be written and what the plugin manager should do to support a plugin. Zgenom does support most paragraphs of this standard. (1-3 & 7-9 as of this writing). The unsupported paragraphs are all related to unloading (which isn't currently supported) and a hook for plugins that the plugin manager should call on updates (you probably shouldn't use zgenom if your plugin requires this). **Note:** *Paragraph 3* says to add every `./bin` folder found in a plugin. I personally wouldn't want this so this is off by default. Please set `ZGENOM_AUTO_ADD_BIN=1` before sourcing `zgenom.zsh` to enable this paragraph. ## Releases Every commit which is merged into `main` is considered a stable release. Every open PR is considered a beta release that I test locally. You're welcome to test it on your machine as well. ## Alternatives There are a lot of alternatives. The most popular is probably [antigen](https://github.com/zsh-users/antigen) but it's only in maintenance mode. An extensive list can be found [here](https://github.com/mattmc3/zsh_unplugged#newspaper_roll-current-state). You should think what features you need from a plugin manager. At its purest form it's just `git clone` and `source path/to/plugin/file.zsh`. So nothing you couldn't do yourself. But there are some subtleties that you might not think of. For example the default branch could change (e.g. `master` to `main`) and keep you from updating the plugin without an error message. With `zgenom` I don't even think about zsh plugins. Every seven days `zgenom` and the plugins get updated automatically. `zgenom` can also detect new plugins and install them automatically as well. ## Feedback If you like this plugin, star it! It's a great way of getting feedback. The same goes for reporting issues or feature requests.