I'm using zsh with tmux and it's a bit frustrating to have it appear on every window and every pane. At the same time if it only appears once I might miss it. Does anyone have suggestions on how to make it appear only a handful of times per day?
The problem with the RANDOM approach is that it scales with how many terminals you open on a given day. Compensating for that requires state.
I'm too lazy to write actual code right now, but here's a sketch of a possible solution that allows bursts. This is racy but safely so.
declare N, the burst size. Say, 5.
declare T, the time in seconds after which a new burst can start. Say, 3600.
declare S, the time in seconds after which a new occurrence is allowed within a burst. Say, 10.
declare P, a unique identifier. Say, the-last-sunday.
declare D, the directory to store state in. Say, /tmp/bursty-ratelimiter.
mkdir -p "$D"
if "$D/$P-central" exists and its timestamp is within the last "$S" seconds, exit the process without doing anything else (hmm, I suppose when opening multiple panes at the same time, this race might actually matter ... I guess you could use a lock if it matters that much)
touch (create and update the timestamp of) "$D/$P-central"
for I from 1 to "$N"
if "$D/$P-$I" exists and its timestamp is within the last "$T" seconds, continue with the next iteration
touch "$D/$P-$I"
run the rest of the program under load
exit the process without doing anything