brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmux wait-for blocks a script until another pane sends a signal

Tmux
~/tips/tip-tmux-wait-for-signal

tmux wait-for build-done

Pauses a command until something in another pane says it's done, without polling or sleep.

Plenty of scripts start something in a tmux pane and then sleep 30 and hope. tmux has a proper way to wait: named channels.

tmux wait-for build-done

That command just sits there. It returns when something, anywhere on the same tmux server, runs:

tmux wait-for -S build-done

The name is free to choose. A typical use is a script that sends a long job to another pane and then waits for it:

tmux send-keys -t build 'make all; tmux wait-for -S build-done' Enter
tmux wait-for build-done
echo "build finished"

With a one second job, the waiting command returns after about a second, which is the time the other pane needs. The other order works too. When the signal comes first, the next wait-for on that name returns at once, so you don’t lose a signal if the job finishes before you start waiting.

Caveats: the signal is sent whether the job succeeded or not, since the ; in the example always continues. Use && or send a different channel name when it fails. The channel name is shared across the whole server, so pick names that won’t collide. There are also -L and -U to lock and unlock a channel, if you want to use it as a mutex between scripts.

Further reading: tmux manual, wait-for

More Tmux tips tmux new -d -s report -x 200 -y 50 'top' set -g allow-passthrough on tmux kill-server Ctrl-b [ tmux new -s scratch \; set destroy-unattached on All Tmux tips (125) All topics

Link