22

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?

jazzjazzy
  • 412
  • 3
  • 20
  • 15
    Not really the solution, but any pane set in a different mode (e.g. clock mode, copy mode, showing help) will not respond to key strokes. If you need all but a couple of panes to synchronize, this works pretty well. – Edd Steel Jan 04 '13 at 18:52
  • I was thinking about how to do this... I was considering a nested tmux session – Steve Buzonas Nov 12 '14 at 22:40
  • @EddSteel Actually it is a better solution than the only answer posted here. Nice tip! – mostruash Oct 12 '15 at 11:50

2 Answers2

8

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

Madhav Prabhoo
  • 306
  • 2
  • 5
5

You can disable input on panes with select-pane -d. To enable it again, do select-pane -e

I have a shortcut for this in my prefix:

bind -T marcos d select-pane -d
bind -T marcos e select-pane -e
Marcos Oliveira
  • 449
  • 4
  • 4