Launching Dev Dependencies with tmux

When working on CollBox, we have a handful of external services the app depends on which we need to have running at development time. I used to run these via Foreman, but somewhere along the way my Ruby installation seems to have gotten borked (thanks, Catalina?) and since then I’ve been running the services by hand. I always work in a tmux session anyway, so I decided it was time to see what it would look like to launch my window full of dependencies in tmux from a script.

As it turns out, tmux is fantastically scriptable. If you simply run tmux <command> from a shell inside of a tmux session, that command will be run by the encapsulating tmux instance, and these are the same set of commands that can be bound to your tmux keyboard shortcuts. You can also simply send a stream of keystrokes to panes inside of tmux. All of this means running my four dependencies in a single window (named “deps”) under their own panes is as simple as:

#!/bin/sh
# deps.sh

tmux new-window -n "deps"

tmux send-keys "redis-server redis.conf" Enter
tmux split-window
tmux send-keys "datomic/bin/transactor transactor.properties" Enter
tmux split-window
tmux send-keys "lein shadow-watch" Enter
tmux split-window
tmux send-keys "npx gulp" Enter

tmux select-layout tiled

When I’m ready to work on the project I simply run ./deps.sh at my shell and I end up with something like this:

+---------------------------------+---------------------------------+
| $ redis-server redis.conf       | $ datomic/bin/transactor transa |
| ...                             | ...                             |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
|---------------------------------+---------------------------------|
| $ lein shadow-watch             | $ npx gulp                      |
| ...                             | ...                             |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
|                                 |                                 |
+---------------------------------+---------------------------------+
| 1:deps* | 2:zsh |                                                 |
+-------------------------------------------------------------------+

fin.


A few thoughts on other tools that can be used to address this same problem: