简体   繁体   中英

How do I source my shell rc file (~/.bashrc, ~/.zshrc, etc) in all tmux panes in all windows in a tmux session?

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 (eg I don't have to worry about unsetting any tmux options that the command set)

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM