Joining Sessions in tmux

Posted on April 1, 2021

I have been a tmux user for long time now. Oddly enough I haven’t tinkered with my tmux config from when I first crafted it. Probably just updated once when a tmux upgrade broke the config.

Recently I wanted to merge windows of one session into another.

I wrote a small script to achieve this:


dest_session_window_count="$(tmux list-windows -t "$dest_session_id" -F "#{window_index}" | tail -n1)"
for i in $(tmux list-windows -t $source_session_id -F "#{window_index}"); 
dest_session_window_count=$(($dest_session_window_count + 1))
echo $dest_session_window_count
tmux move-window -s $source_session_id:$i -t $dest_session_id:$dest_session_window_count

The input to this script is session id of the windows that you want to merge from and session id to merge to.