-
Notifications
You must be signed in to change notification settings - Fork 491
Description
pretty much just did the following 2 easy steps:
the pane populator
a bash file in my ~/lib/bash/ directory, called tmux_027_populator.sh (you can call it whatever you want — i called it this specifically because the commands on panes 0, 2 and 7 respectively, are the ones i'm having trouble restoring*).
inside this file, i have the following contents:
sleep 1
tmux selectp -t 0 && sleep 0.4 && tmux send-keys "htop -C" C-m && \
tmux selectp -t 2 && sleep 0.4 && tmux send-keys "evilping" C-m && \
tmux selectp -t 7 && sleep 0.4 && tmux send-keys "cmatrix -bs -C white" C-m && \
tmux selectp -t 1
the first line is just a "temporal safeguard" to avoid a race hazard.
the payload basically consists of a sequence that
1.-selects a pane by its number
&&
2.-sleeps for a bit, again to avoid a race hazard&&
3.-sends a bunch of keys, inside of the quotes, which in this case corresponds to your command, and then sends the↵ Enterkey (C-m)&&
the last line just resets the "focus" to pane 1 (since i enter a password there)
the caller
an entry at the bottom of the ~/.tmux.conf file, that calls on this "pane populator" script, like so:
#==================================================
# shell commands
#==================================================
run -b -t 0 "~/lib/bash/tmux_027_populator.sh"
that's it?
that's it.
how it works
each time tmux starts, it will run the script. the script will jump around between the panes and execute all the commands. it works using tmux's internal run-shell command. you can read more about it using man tmux | grep -A 5 run-shell:
run-shell [-b] [-t target-pane] shell-command
(alias: run)
Execute shell-command in the background without creating a window. Before being executed, shell-command is expanded using the rules specified in the FORMATS section. With -b, the command is run in the background. After it finishes, any output to stdout is displayed in copy mode (in the pane specified by -t or the current pane if omitted). If the command doesn't return success, the exit status is also displayed.
this solution is far from perfect, but it works fairly well and can be easily adapted to different scenarios.
additional shtuff
*how to get a pane's number? <prefix> + q