Files
CodeSnippets/bash/tmux_launcher.bash
2022-07-11 14:03:17 +09:30

29 lines
1.5 KiB
Bash

#!/bin/bash
tmux new -s sessionname -d # create new session with a name and detach
tmux rename-window -t sessionname:0 "This is window foo." # rename (default) window 0 of foo to something cool
tmux split-window -t sessionname:0 -v -p 60 # split into top and bottom panes with 60/40 row split
tmux send-keys -t sessionname:0.0 'top' 'C-m' # run a thing in the top pane, can use 'C-m' or 'Enter'
tmux send-keys -t sessionname:0.1 'script.bs $@' 'C-m' # run another thing in the bottom pane, passing through cli arguments
tmux attach -t sessionname # jump into the active session to watch things happen
tmux send-keys -t sessionname:0.0 'q' 'C-m' # tell 'top' in top pane to quit (C-m probably not needed here...)
tmux kill-session -t sessionname # close tmux session
# NOTE: need the following at the end of 'script.bs' to make it drop out, first two lines are optional but a good way to hold
# the session open until user is ready to close it, last line is the kick back to this higher level tmux wrapper.
#
# echo "Press any key to close the window."
# read -s -n1
# tmux detach
#
# If you can also call script.bs NOT from the tmux wrapper, then only do the above if you're actually insidie a tmux.
# This works because tmux handily sets the TMUX variable so you can trivially check.
#
# if [ "$TMUX" ]; then
# echo "Press any key to close the window."
# read -s -n1
# tmux detach
# fi