Tmux synchronize some but not all panes

tmux

In tmux I have a 3 columns and 2 rows layout, the top row is ssh connection to all my server and the bottom is all the same servers running top.

I am trying to sync the top row so if I enter a command all three panes copy the same command, I tried synchronize-panes but as the man pages says it will run the commands through all the panes which then plays havoc with my all my 'top' on the botton row.

is there anyway to sync a set of panes?

Best Answer

It's not exactly what you're looking for but it is pretty close. The idea is to bind a key to a set of commands to:

  1. Prompt for the command to run
  2. Use 'select-pane' to chose the first top level pane
  3. Use 'send-keys' to run the command
  4. Repeat steps 2 and 3 for other top level panes

Here is how the command looks like

bind R command-prompt -p "Command :" "select-pane -t 0 \; send-keys "%1" C-m \; select-pane -t 2 \; send-keys "%1" C-m \; select-pane -t 4 \; send-keys "%1" C-m "

Following is a complete example, let's setup the 6 panes, 2 rows of 3 each :

$ tmux new -s 'top_n_tail' \; split-window -h \; split-window -h \; select-layout even-horizontal \; detach
$ tmux att -t 'top_n_tail' \; select-pane -t 0 \; split-window \; detach
$ tmux att -t 'top_n_tail' \; select-pane -t 2 \; split-window \; detach
$ tmux att -t 'top_n_tail' \; select-pane -t 4 \; split-window

On tmux prompt (C-b :) bind 'R' to a set of tmux commands which accept your bash command and send it to some panes:

:bind R command-prompt -p "Command :" "select-pane -t 0 \; send-keys "%1" C-m \; select-pane -t 2 \; send-keys "%1" C-m \; select-pane -t 4 \; send-keys "%1" C-m "

Now when you hit C-b R, you'll be prompted for a command

Prompt to enter command

Which will run only in the top 3 panes

Related Topic