Created
January 10, 2026 09:29
-
-
Save chmouel/965fa1ba01558bb5e9d11135cec9009d to your computer and use it in GitHub Desktop.
Jump to zellij session with fzf and zsh completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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