feat(zellij): add zellij plugin (#13624)

This commit is contained in:
Hobeom Jeon authored and GitHub committed 2026-11-27 14:54:06 -08:00
1 parent 1dc43bfe53
commit 90e5779f1f
2 files changed
+120

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# zellij
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)
```
## Aliases
| Alias | Command | Description |
| ------ | ---------------------------- | --------------------------- |
| `zj` | `zellij` | Zellij command |
| `zjl` | `zellij list-sessions` | List sessions |
| `zjs` | `zellij -s` | Start a named session |
| `zjda` | `zellij delete-all-sessions` | Delete all sessions |
| `zjka` | `zellij kill-all-sessions` | Kill all sessions |
| `zjr` | `zellij run` | Run a command in a pane |
| `zjad` | `zellij action detach` | Detach from current session |
## Functions
| Function | Command | Description |
| -------- | -------------------------------- | -------------------------------- |
| `zja` | `zellij attach` | Attach to a session |
| `zjd` | `zellij delete-session` | Delete a session (exited only) |
| `zjdf` | `zellij delete-session --force` | Force-delete any session |
| `zjk` | `zellij kill-session` | Kill a session |
| `zjas` | `zellij action switch-session` | Switch to a session |
| `zjrf` | `zellij run --floating --` | Run a command in a floating pane |
| `zje` | `zellij edit` | Edit a file in a pane |
## Completions
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. The cache is written to a temporary file and moved into place, so a
partially written file is never loaded.
Session-aware completions are provided for `zja`, `zjdf` and `zjas` (all sessions), `zjk`
(running sessions) and `zjd` (exited sessions).
+77
View File
@@ -0,0 +1,77 @@
if (( ! $+commands[zellij] )); then
return
fi
# Aliases
alias zj='zellij'
alias zjl='zellij list-sessions'
alias zjs='zellij -s'
alias zjda='zellij delete-all-sessions'
alias zjka='zellij kill-all-sessions'
alias zjr='zellij run'
alias zjad='zellij action detach'
# Functions (with session-aware completion)
function zja { command zellij attach "$@"; }
function zjd { command zellij delete-session "$@"; }
function zjdf { command zellij delete-session --force "$@"; }
function zjk { command zellij kill-session "$@"; }
function zjas { command zellij action switch-session "$@"; }
# Convenience functions
function zjrf { command zellij run --floating -- "$@"; }
function zje { command zellij edit "$@"; }
# Completion cache: generate synchronously on first load, regenerate in the
# background when the zellij binary is newer than the cache. Write to a temp
# file in the same directory and rename it, so a partial file is never loaded.
_omz_zellij_gen_completion() {
local TMPPREFIX="$ZSH_CACHE_DIR/completions/._zellij"
zf_mv -f -- =( command zellij setup --generate-completion zsh 2>/dev/null ) "$ZSH_CACHE_DIR/completions/_zellij"
}
zmodload -F zsh/files b:zf_mv
if [[ ! -s "$ZSH_CACHE_DIR/completions/_zellij" ]]; then
_omz_zellij_gen_completion
elif [[ $commands[zellij] -nt "$ZSH_CACHE_DIR/completions/_zellij" ]]; then
_omz_zellij_gen_completion &|
fi
_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 \
|| _omz_zellij_ls_raw | LC_ALL=C sed -nE 's/^([^[:space:]]+).*/\1/p'
}
_omz_zellij_all_sessions() {
emulate -L zsh
local -a sessions
sessions=(${(f)"$(_omz_zellij_session_names)"})
(( ${#sessions} )) && compadd -Q -a sessions
}
_omz_zellij_running_sessions() {
emulate -L zsh
local -a sessions
sessions=(${(f)"$(_omz_zellij_ls_raw | LC_ALL=C sed -nE '/\(EXITED/!s/^([^[:space:]]+).*/\1/p')"})
(( ${#sessions} )) && compadd -Q -a sessions
}
_omz_zellij_exited_sessions() {
emulate -L zsh
local -a sessions
sessions=(${(f)"$(_omz_zellij_ls_raw | 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
compdef _omz_zellij_all_sessions zja zjdf zjas
compdef _omz_zellij_running_sessions zjk
compdef _omz_zellij_exited_sessions zjd
fi