This is the fourth and last in a series of posts describing the system I built to monitor long-running commands.
The third post explained my
mon script, which together
twait script from the second post,
lights up an LED when a command in a tmux pane or iTerm window completes.
If I want to monitor a command, I use
mon twait ID, where
ID is the pane or
window ID. Or I can run another command only if the first command is successful,
twait ID && ./other_command.
Of course it would be annoying to type the window ID manually, so I have two
keyboard shortcuts. One to start
mon twait ID in a separate window that closes
automatically when it is done. The other to open a new window with the text
twait ID && followed by a space.
Tmux can be scripted through the use of unix-like commands, with arguments and options. These can either be run from the command line or assigned keyboard shortcuts.
I use Ctrl-A plus uppercase E for the first.
This splits to form a new window, 5 lines high, and runs
mon twait. The
parameter in a
tmux run command gets translated into the pane ID.
I use Ctrl-A plus lowercase E for the second.
You can do very similar things with iTerm using AppleScript.
To open the monitor in a temporary pane, I use this script. It is possible to control the height of the new pane, but I haven’t figured it out yet.
I prefer new windows over tabs or split windows, so I use this script to open a new window prepped to run a follow-up command.