Simple | Small | Stable | Secure

List and open tmux session with rofi

This article assume that you already know about rofi [1] and tmux [2].

In rofi you can list ssh client using command rofi -show ssh, and when selecting one of it will create new terminal and start opening ssh connection to selected server. But what if we want to start or create new tmux session using predefined list of session name like this one:


Lets start by creating a zsh script as module that can be executed by rofi.

First, create new file ~/bin/

Create or modify rofi config, ~/.config/rofi/config, by adding our custom tmuxopen

! "Enabled modi" Set from: Default
rofi.modi: window,run,ssh,tmuxopen:~/bin/

Next we start creating script. Open the script file and create an associative array to map session name with their working directory,

#!/usr/bin/env zsh

typeset -A session_map

  tesis    $HOME/tesis
  projectA $HOME/workspaces/projectA

We collect the key from our session_map to be displayed on rofi.

typeset -a session_name

for k v in "${(@kv)session_map}"; do
	session_names=($k $session_names)

The first time rofi execute our script, it will pass it with no parameter ( $# -eq 0 ), so what we will do is send the list of session name as an input to be displayed by rofi.

if [[ $# -eq 0 ]]; then
	echo "$session_names" | tr ' ' '\n' | sort -n
	exit 0

Each item must be separated by newline (\n), thats why we replace single space with newline, and that is why your session name should not have space in them.

When you select one of the item in list, rofi will execute the script again with parameter, just like we call the script from terminal. So, what we will do was,

  • catch the first parameter,

  • check if its exist in our session mapping,

  • and get their working directory.


## - Check if user selection match with session mapping.
## - Get session working directory
for k v in "${(@kv)session_map}"; do
	if [[ "$k" == "$SELECTED" ]]; then

if (( $FOUND == 0 )); then
	echo "Unknown session name $1"
	exit 1

Last code was spawning new terminal to open new tmux session with working directory set to TMUXDIR

$TERMINAL -e tmux new -c $TMUXDIR -As $SELECTED >/dev/null &

Thats it.