29

Is a way to send the same command to all window in tmux, not to all pane in window. synchronize-panes - send command to all pane in one window. I need something like 'at' in screen.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
vorand
  • 291
  • 1
  • 3
  • 3

2 Answers2

23

You could always do something like this:

session=mysession
message="hello world"
tmux list-windows -t $session|cut -d: -f1|xargs -I{} tmux send-keys -t $session:{} $message

You could also bind this to a key in your tmux.conf like this:

bind C-e command-prompt -p "session?,message?" "run-shell \"tmux list-windows -t %1 \| cut -d: -f1\|xargs -I\{\} tmux send-keys -t %1:\{\} %2\""
Alex Gaudio
  • 1,894
  • 1
  • 16
  • 13
  • 1
    This is great - a little addition. I wanted to do the same thing, but to send the same output to all panes in each window. Easily done with the `synchronize-panes` setting! – dsummersl Feb 01 '13 at 00:47
  • 1
    You also get current session by command: `tmux display -p "#S"` – NgaNguyenDuy Jul 25 '16 at 00:55
  • If you want to actually execute the command, add `Enter` to the above command. But then it will remove spaces in the message. You can make a function like this to deal with these points: `function keys { tmux list-windows -t $session|cut -d: -f1|xargs -I{} tmux send-keys -t $session:{} "$@" Enter}`. See [this question](https://superuser.com/questions/492266/run-or-send-a-command-to-a-tmux-pane-in-a-running-tmux-session) and [this question](https://stackoverflow.com/questions/15714984/bash-function-with-tmux-send-keys), respectively, for more. But the github solution below is more thorough! – Blue Raspberry Nov 01 '18 at 20:53
2

You could do something like this: https://gist.github.com/2773454

But this executes for every pane, but you could adjust accordingly.

All depends what your trying to accomplish, for this an example of what i want to accomplish is to source ~/.zsh in all panes.

DebugXYZ
  • 905
  • 1
  • 10
  • 17