Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created January 10, 2026 09:29
Show Gist options
  • Select an option

  • Save chmouel/965fa1ba01558bb5e9d11135cec9009d to your computer and use it in GitHub Desktop.

Select an option

Save chmouel/965fa1ba01558bb5e9d11135cec9009d to your computer and use it in GitHub Desktop.
Jump to zellij session with fzf and zsh completion
function z() {
if [[ -n ${1} ]]; then
zellij attach -c ${1}
else
local session
nmb=$(zellij list-sessions -n|grep -cv EXITED)
[[ ${nmb} == 0 ]] && return
(( nmb += 2 ))
session=$(zellij list-sessions -r|grep -v EXITED | fzf --ghost "Zellij Session" --ansi -0 --height=${nmb} || return)
[[ -n ${session} ]] && zellij attach -c "${session%% *}"
fi
}
_z() {
local sessions=()
while IFS= read -r line; do
[[ $line == *EXITED* ]] && continue
local name="${line%% *}"
local desc="${line#* }"
sessions+=("$name:$desc")
done < <(zellij list-sessions -r --no-formatting 2>/dev/null)
_describe -V 'sessions' sessions
}
compdef _z z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment