From c733b0af5392f85af5544d43eb11a91adf405bf9 Mon Sep 17 00:00:00 2001 From: Hobeom Date: Mon, 9 Mar 2026 20:28:55 +0900 Subject: [PATCH 1/8] 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" &| From 6b292d300eb1c65729e720636108fa98dc038500 Mon Sep 17 00:00:00 2001 From: Hobeom Date: Mon, 9 Mar 2026 21:00:38 +0900 Subject: [PATCH 2/8] fix(zellij): change default prefix from z to zj Avoid conflicts with popular directory jumpers (zoxide, z.lua, etc.) by defaulting to "zj". Users can opt into "z" via ZSH_ZELLIJ_PREFIX_Z. Co-Authored-By: Claude Opus 4.6 --- plugins/zellij/README.md | 34 +++++++++++++++++++------------- plugins/zellij/zellij.plugin.zsh | 8 ++++---- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index 1fed84734..1a9a7ee9e 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -9,23 +9,29 @@ 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`. +The default alias prefix is `zj`. To use the shorter `z` prefix instead, set the following +variable before oh-my-zsh is sourced: + +```zsh +ZSH_ZELLIJ_PREFIX_Z=true +``` + +> **Note:** If `z` is already aliased by another plugin (e.g., zoxide), the prefix stays `zj` +> even when `ZSH_ZELLIJ_PREFIX_Z` is set. ## 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 | +| Alias (default) | Alias (with `z`) | Command | Description | +| ---------------- | ---------------- | ---------------------------- | ------------------------ | +| `zj` | `z` | `zellij` | Zellij command | +| `zja` | `za` | `zellij attach` | Attach to a session | +| `zjd` | `zd` | `zellij delete-session` | Delete a session | +| `zjda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | +| `zjk` | `zk` | `zellij kill-session` | Kill a session | +| `zjka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | +| `zjl` | `zl` | `zellij list-sessions` | List sessions | +| `zjr` | `zr` | `zellij run` | Run a command in a pane | +| `zjs` | `zs` | `zellij -s` | Start a named session | ## Completions diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index 02ac259df..e9c5eae89 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -2,11 +2,11 @@ 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 +# Dynamic prefix: use "zj" by default, use "z" if ZSH_ZELLIJ_PREFIX_Z is set and "z" is available +if [[ -n "$ZSH_ZELLIJ_PREFIX_Z" ]] && (( ! $+aliases[z] )); then _zellij_prefix="z" +else + _zellij_prefix="zj" fi # Aliases From e56446195832f7abaadf6a5597e5d4ae3937b4f0 Mon Sep 17 00:00:00 2001 From: Hobeom Date: Mon, 9 Mar 2026 22:57:30 +0900 Subject: [PATCH 3/8] feat(zellij): add session functions, convenience commands, and smart completions - Use functions for attach/delete/kill to enable session-aware completions - Add zr, zrf, ze convenience functions with conflict detection - Improve z prefix collision check (aliases, functions, commands) - Cache completions synchronously on first load, background on updates - Update README to document new functions and completion behavior Co-Authored-By: Claude Opus 4.6 --- plugins/zellij/README.md | 44 ++++++++++----- plugins/zellij/zellij.plugin.zsh | 92 ++++++++++++++++++++++++-------- 2 files changed, 101 insertions(+), 35 deletions(-) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index 1a9a7ee9e..c4c8fd2ea 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -1,7 +1,8 @@ # 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. +This plugin provides aliases, functions, 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) @@ -16,25 +17,42 @@ variable before oh-my-zsh is sourced: ZSH_ZELLIJ_PREFIX_Z=true ``` -> **Note:** If `z` is already aliased by another plugin (e.g., zoxide), the prefix stays `zj` -> even when `ZSH_ZELLIJ_PREFIX_Z` is set. +> **Note:** If `z` is already defined as an alias, function, or command by another plugin +> (e.g., zoxide), the `zj` prefix is used for the main `zellij` alias even when +> `ZSH_ZELLIJ_PREFIX_Z` is set. ## Aliases | Alias (default) | Alias (with `z`) | Command | Description | | ---------------- | ---------------- | ---------------------------- | ------------------------ | | `zj` | `z` | `zellij` | Zellij command | -| `zja` | `za` | `zellij attach` | Attach to a session | -| `zjd` | `zd` | `zellij delete-session` | Delete a session | -| `zjda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | -| `zjk` | `zk` | `zellij kill-session` | Kill a session | -| `zjka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | | `zjl` | `zl` | `zellij list-sessions` | List sessions | -| `zjr` | `zr` | `zellij run` | Run a command in a pane | | `zjs` | `zs` | `zellij -s` | Start a named session | +| `zjda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | +| `zjka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | +| `zjr` | — | `zellij run` | Run a command in a pane | + +## Functions + +| Function (default) | Function (with `z`) | Command | Description | +| ------------------- | ------------------- | ------------------------------ | --------------------------------- | +| `zja` | `za` | `zellij attach` | Attach to a session | +| `zjd` | `zd` | `zellij delete-session` | Delete a session | +| `zjk` | `zk` | `zellij kill-session` | Kill a session | + +The following convenience functions are always available (unless the name is already taken): + +| Function | Command | Description | +| -------- | ---------------------------- | ---------------------------------- | +| `zr` | `zellij run --` | Run a command in a pane | +| `zrf` | `zellij run --floating --` | Run a command in a floating pane | +| `ze` | `zellij edit` | Edit a file in a pane | ## 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. +This plugin caches the zellij completion script. On first load the cache is generated +synchronously; subsequent updates (when the `zellij` binary is newer than the cache) happen in +the background. + +Session-aware completions are provided for `attach`, `delete-session`, and `kill-session` +functions — only relevant sessions (all, running, or exited) are offered. diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index e9c5eae89..34245e56a 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -2,34 +2,82 @@ if (( ! $+commands[zellij] )); then return fi -# Dynamic prefix: use "zj" by default, use "z" if ZSH_ZELLIJ_PREFIX_Z is set and "z" is available -if [[ -n "$ZSH_ZELLIJ_PREFIX_Z" ]] && (( ! $+aliases[z] )); then - _zellij_prefix="z" +if [[ -n ${ZSH_ZELLIJ_PREFIX_Z:-} ]]; then + _zellij_prefix=z else - _zellij_prefix="zj" + _zellij_prefix=zj 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' + +if [[ -n ${ZSH_ZELLIJ_PREFIX_Z:-} ]] && (( ! $+aliases[z] && ! $+functions[z] && ! $+commands[z] )); then + alias z='zellij' +else + alias zj='zellij' +fi + +# alias ${_zellij_prefix}='zellij' alias ${_zellij_prefix}l='zellij list-sessions' -alias ${_zellij_prefix}r='zellij run' alias ${_zellij_prefix}s='zellij -s' +alias ${_zellij_prefix}da='zellij delete-all-sessions' +alias ${_zellij_prefix}ka='zellij kill-all-sessions' +[[ $_zellij_prefix != z ]] && alias ${_zellij_prefix}r='zellij run' -unset _zellij_prefix +eval "${_zellij_prefix}a() { command zellij attach \"\$@\"; }" +eval "${_zellij_prefix}d() { command zellij delete-session \"\$@\"; }" +eval "${_zellij_prefix}k() { command zellij kill-session \"\$@\"; }" -# 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 +(( $+functions[zr] || $+aliases[zr] || $+commands[zr] )) || zr() { command zellij run -- "$@"; } +(( $+functions[zrf] || $+aliases[zrf] || $+commands[zrf] )) || zrf() { command zellij run --floating -- "$@"; } +(( $+functions[ze] || $+aliases[ze] || $+commands[ze] )) || ze() { command zellij edit "$@"; } + +_ZELLIJ_COMP_FILE="${ZSH_CACHE_DIR}/completions/_zellij" +mkdir -p "${_ZELLIJ_COMP_FILE:h}" + +if [[ ! -s $_ZELLIJ_COMP_FILE ]]; then + command zellij setup --generate-completion zsh >| "$_ZELLIJ_COMP_FILE" 2>/dev/null +elif [[ $commands[zellij] -nt $_ZELLIJ_COMP_FILE ]]; then + command zellij setup --generate-completion zsh >| "$_ZELLIJ_COMP_FILE" 2>/dev/null &! fi -zellij setup --generate-completion zsh >| "$ZSH_CACHE_DIR/completions/_zellij" &| +_omz_zellij_ls_raw() { + command zellij list-sessions --no-formatting 2>/dev/null || command zellij list-sessions 2>/dev/null +} + +_omz_zellij_all_sessions() { + emulate -L zsh + local out + local -a sessions + out="$(_omz_zellij_ls_raw)" + sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE 's/^([^[:space:]]+).*/\1/p')}") + (( ${#sessions[@]} )) && compadd -Q -a sessions +} + +_omz_zellij_running_sessions() { + emulate -L zsh + local out + local -a sessions + out="$(_omz_zellij_ls_raw)" + sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/EXITED/!s/^([^[:space:]]+).*/\1/p')}") + (( ${#sessions[@]} )) && compadd -Q -a sessions +} + +_omz_zellij_exited_sessions() { + emulate -L zsh + local out + local -a sessions + out="$(_omz_zellij_ls_raw)" + sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/EXITED/s/^([^[:space:]]+).*/\1/p')}") + (( ${#sessions[@]} )) && compadd -Q -a sessions +} + +if (( $+functions[compdef] )); then + autoload -Uz _zellij + compdef _zellij zellij ${_zellij_prefix} ${_zellij_prefix}l ${_zellij_prefix}s + [[ $_zellij_prefix != z ]] && compdef _zellij ${_zellij_prefix}r + compdef _omz_zellij_all_sessions ${_zellij_prefix}a + compdef _omz_zellij_running_sessions ${_zellij_prefix}k + compdef _omz_zellij_exited_sessions ${_zellij_prefix}d +fi + +unset _ZELLIJ_COMP_FILE +unset _zellij_prefix From 15fbdaab58e349d23908666f94690e9ef4ae603f Mon Sep 17 00:00:00 2001 From: Hobeom Date: Mon, 9 Mar 2026 22:59:45 +0900 Subject: [PATCH 4/8] refactor(zellij): separate root alias from sub-command prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split _zellij_root_alias and _zellij_short_prefix so that when z is taken (e.g. by zoxide), only the root alias falls back to zj while sub-commands keep the shorter z prefix (zl, za, zk, zd, …). Every alias and function now checks for conflicts before defining, and compdef targets are collected dynamically to avoid binding completions to names that were never created. Co-Authored-By: Claude Opus 4.6 --- plugins/zellij/README.md | 44 +++++++------ plugins/zellij/zellij.plugin.zsh | 103 +++++++++++++++++++++++-------- 2 files changed, 103 insertions(+), 44 deletions(-) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index c4c8fd2ea..c91d2c880 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -10,35 +10,43 @@ plugins=(... zellij) ## Dynamic prefix -The default alias prefix is `zj`. To use the shorter `z` prefix instead, set the following -variable before oh-my-zsh is sourced: +The default prefix is `zj`. To use the shorter `z` prefix instead, set the following variable +before oh-my-zsh is sourced: ```zsh ZSH_ZELLIJ_PREFIX_Z=true ``` -> **Note:** If `z` is already defined as an alias, function, or command by another plugin -> (e.g., zoxide), the `zj` prefix is used for the main `zellij` alias even when -> `ZSH_ZELLIJ_PREFIX_Z` is set. +When `ZSH_ZELLIJ_PREFIX_Z` is set, the root alias (`z`) and sub-command prefix are handled +separately: + +- If `z` is **not** taken → `z`=zellij, sub-commands use `z` prefix (`zl`, `za`, …) +- If `z` **is** taken (e.g., by zoxide) → `zj`=zellij, but sub-commands still use `z` prefix (`zl`, `za`, …) + +This means only the root alias falls back to `zj`; the shorter sub-command shortcuts remain +usable. + +All aliases and functions perform a conflict check before being defined — if a name is already +taken by another alias, function, or command, it is silently skipped. ## Aliases -| Alias (default) | Alias (with `z`) | Command | Description | -| ---------------- | ---------------- | ---------------------------- | ------------------------ | -| `zj` | `z` | `zellij` | Zellij command | -| `zjl` | `zl` | `zellij list-sessions` | List sessions | -| `zjs` | `zs` | `zellij -s` | Start a named session | -| `zjda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | -| `zjka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | -| `zjr` | — | `zellij run` | Run a command in a pane | +| Alias (default) | Alias (with `z`) | Alias (`z` + conflict) | Command | Description | +| ---------------- | ---------------- | ---------------------- | ---------------------------- | ------------------------ | +| `zj` | `z` | `zj` | `zellij` | Zellij command | +| `zjl` | `zl` | `zl` | `zellij list-sessions` | List sessions | +| `zjs` | `zs` | `zs` | `zellij -s` | Start a named session | +| `zjda` | `zda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | +| `zjka` | `zka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | +| `zjr` | — | — | `zellij run` | Run a command in a pane | ## Functions -| Function (default) | Function (with `z`) | Command | Description | -| ------------------- | ------------------- | ------------------------------ | --------------------------------- | -| `zja` | `za` | `zellij attach` | Attach to a session | -| `zjd` | `zd` | `zellij delete-session` | Delete a session | -| `zjk` | `zk` | `zellij kill-session` | Kill a session | +| Function (default) | Function (with `z`) | Command | Description | +| ------------------- | ------------------- | ------------------------ | -------------------- | +| `zja` | `za` | `zellij attach` | Attach to a session | +| `zjd` | `zd` | `zellij delete-session` | Delete a session | +| `zjk` | `zk` | `zellij kill-session` | Kill a session | The following convenience functions are always available (unless the name is already taken): diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index 34245e56a..f79ff420a 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -2,36 +2,82 @@ if (( ! $+commands[zellij] )); then return fi +_omz_zellij_taken() { + (( $+aliases[$1] || $+functions[$1] || $+commands[$1] )) +} + +typeset -ga _zellij_comp_targets _zellij_all_session_targets _zellij_running_session_targets _zellij_exited_session_targets +_zellij_comp_targets=() +_zellij_all_session_targets=() +_zellij_running_session_targets=() +_zellij_exited_session_targets=() + if [[ -n ${ZSH_ZELLIJ_PREFIX_Z:-} ]]; then - _zellij_prefix=z + _zellij_short_prefix=z + if _omz_zellij_taken z; then + _zellij_root_alias=zj + else + _zellij_root_alias=z + fi else - _zellij_prefix=zj + _zellij_short_prefix=zj + _zellij_root_alias=zj fi - -if [[ -n ${ZSH_ZELLIJ_PREFIX_Z:-} ]] && (( ! $+aliases[z] && ! $+functions[z] && ! $+commands[z] )); then - alias z='zellij' -else - alias zj='zellij' +if ! _omz_zellij_taken "$_zellij_root_alias"; then + alias ${_zellij_root_alias}='zellij' + _zellij_comp_targets+=("$_zellij_root_alias") fi -# alias ${_zellij_prefix}='zellij' -alias ${_zellij_prefix}l='zellij list-sessions' -alias ${_zellij_prefix}s='zellij -s' -alias ${_zellij_prefix}da='zellij delete-all-sessions' -alias ${_zellij_prefix}ka='zellij kill-all-sessions' -[[ $_zellij_prefix != z ]] && alias ${_zellij_prefix}r='zellij run' +if ! _omz_zellij_taken "${_zellij_short_prefix}l"; then + alias ${_zellij_short_prefix}l='zellij list-sessions' + _zellij_comp_targets+=("${_zellij_short_prefix}l") +fi -eval "${_zellij_prefix}a() { command zellij attach \"\$@\"; }" -eval "${_zellij_prefix}d() { command zellij delete-session \"\$@\"; }" -eval "${_zellij_prefix}k() { command zellij kill-session \"\$@\"; }" +if ! _omz_zellij_taken "${_zellij_short_prefix}s"; then + alias ${_zellij_short_prefix}s='zellij -s' + _zellij_comp_targets+=("${_zellij_short_prefix}s") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}da"; then + alias ${_zellij_short_prefix}da='zellij delete-all-sessions' + _zellij_comp_targets+=("${_zellij_short_prefix}da") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}ka"; then + alias ${_zellij_short_prefix}ka='zellij kill-all-sessions' + _zellij_comp_targets+=("${_zellij_short_prefix}ka") +fi + +if [[ $_zellij_short_prefix != z ]] && ! _omz_zellij_taken "${_zellij_short_prefix}r"; then + alias ${_zellij_short_prefix}r='zellij run' + _zellij_comp_targets+=("${_zellij_short_prefix}r") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}a"; then + eval "${_zellij_short_prefix}a() { command zellij attach \"\$@\"; }" + _zellij_all_session_targets+=("${_zellij_short_prefix}a") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}d"; then + eval "${_zellij_short_prefix}d() { command zellij delete-session \"\$@\"; }" + _zellij_exited_session_targets+=("${_zellij_short_prefix}d") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}k"; then + eval "${_zellij_short_prefix}k() { command zellij kill-session \"\$@\"; }" + _zellij_running_session_targets+=("${_zellij_short_prefix}k") +fi (( $+functions[zr] || $+aliases[zr] || $+commands[zr] )) || zr() { command zellij run -- "$@"; } (( $+functions[zrf] || $+aliases[zrf] || $+commands[zrf] )) || zrf() { command zellij run --floating -- "$@"; } (( $+functions[ze] || $+aliases[ze] || $+commands[ze] )) || ze() { command zellij edit "$@"; } -_ZELLIJ_COMP_FILE="${ZSH_CACHE_DIR}/completions/_zellij" -mkdir -p "${_ZELLIJ_COMP_FILE:h}" +_ZELLIJ_COMP_DIR="${ZSH_CACHE_DIR}/completions" +_ZELLIJ_COMP_FILE="${_ZELLIJ_COMP_DIR}/_zellij" + +mkdir -p "$_ZELLIJ_COMP_DIR" +(( ${fpath[(I)$_ZELLIJ_COMP_DIR]} )) || fpath=("$_ZELLIJ_COMP_DIR" $fpath) if [[ ! -s $_ZELLIJ_COMP_FILE ]]; then command zellij setup --generate-completion zsh >| "$_ZELLIJ_COMP_FILE" 2>/dev/null @@ -57,7 +103,7 @@ _omz_zellij_running_sessions() { local out local -a sessions out="$(_omz_zellij_ls_raw)" - sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/EXITED/!s/^([^[:space:]]+).*/\1/p')}") + sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/\(EXITED/!s/^([^[:space:]]+).*/\1/p')}") (( ${#sessions[@]} )) && compadd -Q -a sessions } @@ -66,18 +112,23 @@ _omz_zellij_exited_sessions() { local out local -a sessions out="$(_omz_zellij_ls_raw)" - sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/EXITED/s/^([^[:space:]]+).*/\1/p')}") + sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE '/\(EXITED/s/^([^[:space:]]+).*/\1/p')}") (( ${#sessions[@]} )) && compadd -Q -a sessions } if (( $+functions[compdef] )); then autoload -Uz _zellij - compdef _zellij zellij ${_zellij_prefix} ${_zellij_prefix}l ${_zellij_prefix}s - [[ $_zellij_prefix != z ]] && compdef _zellij ${_zellij_prefix}r - compdef _omz_zellij_all_sessions ${_zellij_prefix}a - compdef _omz_zellij_running_sessions ${_zellij_prefix}k - compdef _omz_zellij_exited_sessions ${_zellij_prefix}d + compdef _zellij zellij ${_zellij_comp_targets[@]} + (( ${#_zellij_all_session_targets[@]} )) && compdef _omz_zellij_all_sessions ${_zellij_all_session_targets[@]} + (( ${#_zellij_running_session_targets[@]} )) && compdef _omz_zellij_running_sessions ${_zellij_running_session_targets[@]} + (( ${#_zellij_exited_session_targets[@]} )) && compdef _omz_zellij_exited_sessions ${_zellij_exited_session_targets[@]} fi +unset _ZELLIJ_COMP_DIR unset _ZELLIJ_COMP_FILE -unset _zellij_prefix +unset _zellij_root_alias +unset _zellij_short_prefix +unset _zellij_comp_targets +unset _zellij_all_session_targets +unset _zellij_running_session_targets +unset _zellij_exited_session_targets From fe46305436c631c512f038637cf5ba175eef74c2 Mon Sep 17 00:00:00 2001 From: hobe Date: Wed, 25 Mar 2026 13:43:41 +0900 Subject: [PATCH 5/8] feat(zellij): add detach and switch-session shortcuts - Add `ad` alias for `zellij action detach` - Add `as` function for `zellij action switch-session` with session completion --- plugins/zellij/README.md | 14 ++++++++------ plugins/zellij/zellij.plugin.zsh | 10 ++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index c91d2c880..2828466a5 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -38,15 +38,17 @@ taken by another alias, function, or command, it is silently skipped. | `zjs` | `zs` | `zs` | `zellij -s` | Start a named session | | `zjda` | `zda` | `zda` | `zellij delete-all-sessions` | Delete all sessions | | `zjka` | `zka` | `zka` | `zellij kill-all-sessions` | Kill all sessions | -| `zjr` | — | — | `zellij run` | Run a command in a pane | +| `zjr` | — | — | `zellij run` | Run a command in a pane | +| `zjad` | `zad` | `zad` | `zellij action detach` | Detach from current session | ## Functions -| Function (default) | Function (with `z`) | Command | Description | -| ------------------- | ------------------- | ------------------------ | -------------------- | -| `zja` | `za` | `zellij attach` | Attach to a session | -| `zjd` | `zd` | `zellij delete-session` | Delete a session | -| `zjk` | `zk` | `zellij kill-session` | Kill a session | +| Function (default) | Function (with `z`) | Command | Description | +| ------------------- | ------------------- | ---------------------------------- | ---------------------- | +| `zja` | `za` | `zellij attach` | Attach to a session | +| `zjd` | `zd` | `zellij delete-session` | Delete a session | +| `zjk` | `zk` | `zellij kill-session` | Kill a session | +| `zjas` | `zas` | `zellij action switch-session` | Switch to a session | The following convenience functions are always available (unless the name is already taken): diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index f79ff420a..68b599008 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -69,6 +69,16 @@ if ! _omz_zellij_taken "${_zellij_short_prefix}k"; then _zellij_running_session_targets+=("${_zellij_short_prefix}k") fi +if ! _omz_zellij_taken "${_zellij_short_prefix}ad"; then + alias ${_zellij_short_prefix}ad='zellij action detach' + _zellij_comp_targets+=("${_zellij_short_prefix}ad") +fi + +if ! _omz_zellij_taken "${_zellij_short_prefix}as"; then + eval "${_zellij_short_prefix}as() { command zellij action switch-session \"\$@\"; }" + _zellij_all_session_targets+=("${_zellij_short_prefix}as") +fi + (( $+functions[zr] || $+aliases[zr] || $+commands[zr] )) || zr() { command zellij run -- "$@"; } (( $+functions[zrf] || $+aliases[zrf] || $+commands[zrf] )) || zrf() { command zellij run --floating -- "$@"; } (( $+functions[ze] || $+aliases[ze] || $+commands[ze] )) || ze() { command zellij edit "$@"; } From 0f061a2d0d3268ae9aa6c295905422ae46c01883 Mon Sep 17 00:00:00 2001 From: hobe Date: Wed, 25 Mar 2026 13:44:14 +0900 Subject: [PATCH 6/8] feat(zellij): add help function to list registered aliases Type `zjh` (or `zh` with z prefix) to print a quick-reference table. Only aliases and functions that were actually registered are shown, so conflicts with other plugins are reflected accurately. --- plugins/zellij/README.md | 4 ++++ plugins/zellij/zellij.plugin.zsh | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index 2828466a5..c6e9af24e 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -58,6 +58,10 @@ The following convenience functions are always available (unless the name is alr | `zrf` | `zellij run --floating --` | Run a command in a floating pane | | `ze` | `zellij edit` | Edit a file in a pane | +## Help + +Type `zjh` (or `zh` with `z` prefix) to see a summary of all available aliases and functions. + ## Completions This plugin caches the zellij completion script. On first load the cache is generated diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index 68b599008..46ae04e15 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -83,6 +83,35 @@ fi (( $+functions[zrf] || $+aliases[zrf] || $+commands[zrf] )) || zrf() { command zellij run --floating -- "$@"; } (( $+functions[ze] || $+aliases[ze] || $+commands[ze] )) || ze() { command zellij edit "$@"; } +if ! _omz_zellij_taken "${_zellij_short_prefix}h"; then + eval "${_zellij_short_prefix}h() { + printf '\\e[1mzellij plugin aliases\\e[0m\\n' + local -a _entries=( + '${_zellij_root_alias}:zellij' + '${_zellij_short_prefix}l:zellij list-sessions' + '${_zellij_short_prefix}s:zellij -s ' + '${_zellij_short_prefix}a:zellij attach ' + '${_zellij_short_prefix}d:zellij delete-session ' + '${_zellij_short_prefix}k:zellij kill-session ' + '${_zellij_short_prefix}da:zellij delete-all-sessions' + '${_zellij_short_prefix}ka:zellij kill-all-sessions' + '${_zellij_short_prefix}ad:zellij action detach' + '${_zellij_short_prefix}as:zellij action switch-session ' + '${_zellij_short_prefix}r:zellij run' + 'zr:zellij run -- ' + 'zrf:zellij run --floating -- ' + 'ze:zellij edit ' + '${_zellij_short_prefix}h:Show this help' + ) + local entry name cmd + for entry in \"\${_entries[@]}\"; do + name=\"\${entry%%:*}\" + cmd=\"\${entry#*:}\" + (( \$+aliases[\$name] || \$+functions[\$name] )) && printf ' %-8s %s\\n' \"\$name\" \"\$cmd\" + done + }" +fi + _ZELLIJ_COMP_DIR="${ZSH_CACHE_DIR}/completions" _ZELLIJ_COMP_FILE="${_ZELLIJ_COMP_DIR}/_zellij" From f1db1812cb36d23a09451916e0799f4cd8f95a31 Mon Sep 17 00:00:00 2001 From: hobe Date: Wed, 25 Mar 2026 13:44:36 +0900 Subject: [PATCH 7/8] perf(zellij): use --short flag for session name completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `list-sessions --short --no-formatting` (zellij ≥0.44) to extract session names directly, falling back to sed parsing for older versions. --- plugins/zellij/zellij.plugin.zsh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index 46ae04e15..5fc820414 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -128,12 +128,16 @@ _omz_zellij_ls_raw() { command zellij list-sessions --no-formatting 2>/dev/null || command zellij list-sessions 2>/dev/null } +_omz_zellij_session_names() { + # Use --short if available (zellij ≥0.44), fall back to sed parsing + command zellij list-sessions --short --no-formatting 2>/dev/null \ + || printf '%s\n' "$(_omz_zellij_ls_raw)" | LC_ALL=C sed -nE 's/^([^[:space:]]+).*/\1/p' +} + _omz_zellij_all_sessions() { emulate -L zsh - local out local -a sessions - out="$(_omz_zellij_ls_raw)" - sessions=("${(@f)$(printf '%s\n' "$out" | LC_ALL=C sed -nE 's/^([^[:space:]]+).*/\1/p')}") + sessions=("${(@f)$(_omz_zellij_session_names)}") (( ${#sessions[@]} )) && compadd -Q -a sessions } From da2d2102fc0186d3bf7c15338f702e5484fe832d Mon Sep 17 00:00:00 2001 From: hobe Date: Wed, 25 Mar 2026 13:53:06 +0900 Subject: [PATCH 8/8] feat(zellij): add force-delete function with all-session completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add `df` function (`zjdf`/`zdf`) that runs `zellij delete-session --force`, which can delete running sessions without killing them first (zellij ≥0.44). Completes against all sessions, unlike `d` which only shows exited ones. --- plugins/zellij/README.md | 9 +++++---- plugins/zellij/zellij.plugin.zsh | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/zellij/README.md b/plugins/zellij/README.md index c6e9af24e..2af2792c5 100644 --- a/plugins/zellij/README.md +++ b/plugins/zellij/README.md @@ -45,10 +45,11 @@ taken by another alias, function, or command, it is silently skipped. | Function (default) | Function (with `z`) | Command | Description | | ------------------- | ------------------- | ---------------------------------- | ---------------------- | -| `zja` | `za` | `zellij attach` | Attach to a session | -| `zjd` | `zd` | `zellij delete-session` | Delete a session | -| `zjk` | `zk` | `zellij kill-session` | Kill a session | -| `zjas` | `zas` | `zellij action switch-session` | Switch to a session | +| `zja` | `za` | `zellij attach` | Attach to a session | +| `zjd` | `zd` | `zellij delete-session` | Delete a session (exited only) | +| `zjdf` | `zdf` | `zellij delete-session --force` | Force-delete any session | +| `zjk` | `zk` | `zellij kill-session` | Kill a session | +| `zjas` | `zas` | `zellij action switch-session` | Switch to a session | The following convenience functions are always available (unless the name is already taken): diff --git a/plugins/zellij/zellij.plugin.zsh b/plugins/zellij/zellij.plugin.zsh index 5fc820414..e393338e1 100644 --- a/plugins/zellij/zellij.plugin.zsh +++ b/plugins/zellij/zellij.plugin.zsh @@ -64,6 +64,11 @@ if ! _omz_zellij_taken "${_zellij_short_prefix}d"; then _zellij_exited_session_targets+=("${_zellij_short_prefix}d") fi +if ! _omz_zellij_taken "${_zellij_short_prefix}df"; then + eval "${_zellij_short_prefix}df() { command zellij delete-session --force \"\$@\"; }" + _zellij_all_session_targets+=("${_zellij_short_prefix}df") +fi + if ! _omz_zellij_taken "${_zellij_short_prefix}k"; then eval "${_zellij_short_prefix}k() { command zellij kill-session \"\$@\"; }" _zellij_running_session_targets+=("${_zellij_short_prefix}k") @@ -92,6 +97,7 @@ if ! _omz_zellij_taken "${_zellij_short_prefix}h"; then '${_zellij_short_prefix}s:zellij -s ' '${_zellij_short_prefix}a:zellij attach ' '${_zellij_short_prefix}d:zellij delete-session ' + '${_zellij_short_prefix}df:zellij delete-session --force ' '${_zellij_short_prefix}k:zellij kill-session ' '${_zellij_short_prefix}da:zellij delete-all-sessions' '${_zellij_short_prefix}ka:zellij kill-all-sessions'