Skip to content

Instantly share code, notes, and snippets.

@ben-cohen
Created February 16, 2022 13:58
Show Gist options
  • Save ben-cohen/65ebc732f63bdd44d5af3bb2b56a888d to your computer and use it in GitHub Desktop.
Save ben-cohen/65ebc732f63bdd44d5af3bb2b56a888d to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# tmux_pane_wait.sh: Launch an interactive process in a second tmux pane and
# wait for it to complete before continuing the script in the first pane.
#
# Ben Cohen, February 2022.
#
set -x
set -e
if [ -z "$TMUX" ]
then
# If we aren't already in tmux, start this script again in tmux.
tmux new-session -- "$0" "$@"
exit $?
fi
# Do something here before launching the other pane.
echo Initial stuff.
# Start some command in another pane and get its id.
# Signal on the channel "pane_$TMUX_PANE" when finished.
other_pane_id=$(tmux split-window -P -F "#{pane_id}" 'echo "This is tmux pane $TMUX_PANE." ; echo "You can type stuff in here." ; echo ; bash ; tmux wait -S "pane_$TMUX_PANE"')
# Do some more stuff here after launching the other pane.
echo More stuff.
# Maybe this pane will simply block until the other pane is finished...
sleep 1
# ... or perhaps we want it to wait for the signal from the other pane.
tmux wait pane_$other_pane_id
# Do stuff after the other pane has closed.
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment