Created
April 24, 2014 20:10
-
-
Save danielpcox/11267895 to your computer and use it in GitHub Desktop.
Run a command in all tmux panes of the current window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Runs the specified command (all arguments together) in all tmux panes in the current window | |
# Notate which window/pane we were originally at | |
window=`tmux display-message -p '#I'` | |
ORIG_PANE_INDEX=`tmux display-message -p '#P'` | |
command=$@ | |
# Loop through the panes that are in the window | |
for pane in `tmux list-panes -F '#P'`; do | |
# Skip the window that the command was ran in, run it in that window last | |
# since we don't want to suspend the script that we are currently running | |
# and also we want to end back where we started.. | |
if [ $ORIG_PANE_INDEX -eq $pane ]; then | |
continue | |
fi | |
tmux select-pane -t $pane #select the pane | |
# run the command & switch back to the gui if there was any | |
tmux send-keys C-[ "i$command" C-m | |
done | |
tmux select-pane -t $ORIG_PANE_INDEX #select the original pane | |
tmux send-keys C-c C-[ "i$command" C-m |
My version is also for terminals with vi mode, since it ensures that we're in insertion mode before entering the command.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hacked up from https://gist.github.com/deshawnbw/2773454