greymd / tmux-xpanes

Awesome tmux-based terminal divider
MIT License
1.96k stars 61 forks source link

How to create a Tmux and Xpanes session into one splited window? #171

Closed yehiam6 closed 1 year ago

yehiam6 commented 1 year ago

Hey, I'm running a bash script that creates an Xpanes and Tmux sessions based on list of hosts (SSH to each host in the list with some extra arguments). The issue now is that every xpanes command is created in a different window instead of one window with split panes.

If I'm running the same command separately (not via the script) it is work as excepted. What am i missing here? or how can i attached all those windows to one splitted window? Here is my code:

#!/bin/bash

#validate if TMUX session is running
if ! [ -n "$TMUX" ]; then
  echo "This must be run from a Tmux session, please create a Tmux session first"
  exit 0
fi

set +x

for srv in `cat hostsList.txt`; do \
   echo "[$srv]"
   RAND=`echo $srv | md5sum | awk '{print $1}'`
   cp ~/.ssh/id_rsa{,_$RAND}
   cp ~/.ssh/id_rsa{.pub,_$RAND.pub}
   xpanes -c "{}" "<my SSH command>" ;
   rm ~/.ssh/id_rsa_$RAND ~/.ssh/id_rsa_${RAND}.pub &
done
greymd commented 1 year ago

Can you add the -x option and see if it works as desired?

i.e:

for srv in `cat hostsList.txt`; do \
   echo "[$srv]"
   xpanes -x -c "{}" "echo $srv" ;
done
greymd commented 1 year ago

Let me close it. If you need further assistance, please let me know.