From c733b0af5392f85af5544d43eb11a91adf405bf9 Mon Sep 17 00:00:00 2001 From: Hobeom Date: Mon, 9 Mar 2026 20:28:55 +0900 Subject: [PATCH] feat(zellij): add zellij plugin with aliases and completions Add a new plugin for the zellij terminal multiplexer providing: - 9 shorthand aliases with dynamic prefix (z or zj to avoid conflicts) - Background completion caching using the same pattern as the gh plugin Co-Authored-By: Claude Opus 4.6 --- plugins/zellij/README.md | 34 +++++++++++++++++++++++++++++++ plugins/zellij/zellij.plugin.zsh | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 plugins/zellij/README.md create mode 100644 plugins/zellij/zellij.plugin.zsh diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md new file mode 100644 index 000000000..1fed84734 --- /dev/null +++ b/plugins/zellij/README.md @@ -0,0 +1,34 @@ +# zellij + +This plugin provides aliases and completions for [zellij](https://zellij.dev/), the terminal workspace +(multiplexer). To use it, add `zellij` to the plugins array in your zshrc file. + +```zsh +plugins=(... zellij) +``` + +## Dynamic prefix + +The default alias prefix is `z`. If `z` is already taken by another plugin (e.g., the +[suse](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/suse) plugin), the prefix +automatically falls back to `zj`. + +## Aliases + +| Alias | Command | Description | +| ---------- | ---------------------------- | ------------------------ | +| `z`/`zj` | `zellij` | Zellij command | +| `za`/`zja` | `zellij attach` | Attach to a session | +| `zd`/`zjd` | `zellij delete-session` | Delete a session | +| `zda`/`zjda` | `zellij delete-all-sessions` | Delete all sessions | +| `zk`/`zjk` | `zellij kill-session` | Kill a session | +| `zka`/`zjka` | `zellij kill-all-sessions` | Kill all sessions | +| `zl`/`zjl` | `zellij list-sessions` | List sessions | +| `zr`/`zjr` | `zellij run` | Run a command in a pane | +| `zs`/`zjs` | `zellij -s` | Start a named session | + +## Completions + +This plugin caches the zellij completion script in the background (using the same approach as +the [gh](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/gh) plugin). On first load the +cache is generated; completions become available in the next shell session. diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh new file mode 100644 index 000000000..02ac259df --- /dev/null +++ b/plugins/zellij/zellij.plugin.zsh @@ -0,0 +1,35 @@ +if (( ! $+commands[zellij] )); then + return +fi + +# Dynamic prefix: use "z" if no conflict, fall back to "zj" +if (( $+aliases[z] )); then + _zellij_prefix="zj" +else + _zellij_prefix="z" +fi + +# Aliases +alias ${_zellij_prefix}='zellij' +alias ${_zellij_prefix}a='zellij attach' +alias ${_zellij_prefix}d='zellij delete-session' +alias ${_zellij_prefix}da='zellij delete-all-sessions' +alias ${_zellij_prefix}k='zellij kill-session' +alias ${_zellij_prefix}ka='zellij kill-all-sessions' +alias ${_zellij_prefix}l='zellij list-sessions' +alias ${_zellij_prefix}r='zellij run' +alias ${_zellij_prefix}s='zellij -s' + +unset _zellij_prefix + +# Completion caching (same pattern as gh plugin) +# On first load, _zellij may not exist in fpath — autoload fails silently. +# The background command generates the cache file for subsequent sessions. +# Load order: plugin loads → compinit runs → next session picks up cached file. +if [[ ! -f "$ZSH_CACHE_DIR/completions/_zellij" ]]; then + typeset -g -A _comps + autoload -Uz _zellij + _comps[zellij]=_zellij +fi + +zellij setup --generate-completion zsh >| "$ZSH_CACHE_DIR/completions/_zellij" &|