Skip to content

Instantly share code, notes, and snippets.

@danielpcox
Created April 24, 2014 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpcox/11267895 to your computer and use it in GitHub Desktop.
Save danielpcox/11267895 to your computer and use it in GitHub Desktop.
Run a command in all tmux panes of the current window
#!/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
@danielpcox
Copy link
Author

@danielpcox
Copy link
Author

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