Scenario: I edit ~/.zshrc
, and I want to source it in all of my tmux panes, in all windows, in a given session. I want to do this with a keybinding, from any pane.
I tried looking at How to send a command to all panes in tmux?, which used setw synchronize-panes on
and then ran a tmux ex mode command; but I'd like to run source $HOME/.zshrc
, (a shell command), and I'm a little confused as to how to do that.
I'd like it to be a keybinding that I can put into .tmux.conf
, so that I only have to press prefix <key_combo> to perform this, and then everything returns to the way it was before I ran this (e.g. I don't have to worry about unsetting any tmux options that the command set)
CodePudding user response:
This would work for you:
# send "source ~/.bashrc<Enter>" to all panes in *current* session
bind B run 'panes=`tmux list-panes -s -F "##{pane_id}"`; \
for pane in $panes; do \
tmux send -t $pane "source ~/.bashrc" Enter; \
done'
# send "source ~/.zshrc<Enter>" to all panes in *current* session
bind Z run 'panes=`tmux list-panes -s -F "##{pane_id}"`; \
for pane in $panes; do \
tmux send -t $pane "source ~/.zshrc" Enter; \
done'