Manage your Zellij sessions

Quick post on great Zellij tool I’ve been using for some weeks now in Tmux replacement.

I’ve been missing to manage my sessions on multiplexer init while starting a new shell or terminal so I’ve ended creating a quick feature to manage it on startup.

Dependencies

You need sk binary installed and in your $PATH and of course zellij.

Demo

Zellij Sessions

Installation

Add this block at the end of your $SHELLrc file (tested with BASH and ZSH) :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
ZJ_SESSIONS=$(zellij list-sessions)
NO_SESSIONS=$(echo "${ZJ_SESSIONS}" | wc -l)

if [ "{$ZELLIJ}" ] && [ -z "${ZELLIJ_SESSION_NAME}" ]; then
  echo -ne "Active Zellij sessions :\n"
  for i in $(echo "${ZJ_SESSIONS}"); do echo -ne "*${i}\n"; done
  echo -ne '\n'
  read REPLY\?"New zellij session [y/n] ? "
  if [ "${REPLY}" = "y" ]; then
    read SESS\?"Session name : "
    zellij --layout compact attach -c "${SESS}"
  else
    if [ "${NO_SESSIONS}" -ge 1 ]; then
      zellij --layout compact attach \
      "$(echo "${ZJ_SESSIONS}" | sk)"
    else
    fi
  fi
fi

Contributing

Feel free to fork and contribute.

Sources are here.