Lately, I’ve been using tmux a lot. This resulted in me figuring out how to get lein-test-refresh to send notifications using tmux.
The setup linked above works great for when I’m doing work all by myself. It showed a problem when using ssh and tmux to pair with another developer. Instead of both developers receiving a notification, only one did. One is better than none but not ideal.
Below is a GIF showing the problem. Each window simulates a different developer.
This wasn’t too hard to fix. A little digging through the tmux manpage shows that tmux display-message
takes an optional flag telling it which client receives the message. If we can get a list of all the clients then iterating over them and sending a message to each is straightforward.
tmux list-clients
give us this list. Below is the output.
1 2 3 |
|
What we care about are the parts that look like /dev/ttys002
. At first I used cut
to grab these values but then I dug a bit deeper into the tmux
manpage.
It turns out that you can specify a format to tmux list-clients
. Running tmux list-clients -F "#{client_name}"
gives us the output we care about.
1 2 3 |
|
We can combine that with xargs
to send a message to multiple clients.
That command is a bit much to put into lein-test-refresh
’s configuration so I shoved it in a script called notify
and configured lein-test-refresh
to use it. Script and GIF of that below. Now both you and your pair can get notifications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|