Joining Sessions in tmux

Posted on April 1, 2021 by abhinav

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: ```bash merge_session.sh #!/bin/bash

source_session_id=$1 dest_session_id=$2 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}"); do dest_session_window_count=$(($dest_session_window_count + 1)) echo $dest_session_window_count tmux move-window -s sourcesessionid:i -t destsessionid:dest_session_window_count done ```

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