4 ms·
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. D
by _false 3y ago
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?
- accessd 3y agoYou can run it randomly with: (( RANDOM%2 == 0 )) && $HOME/last_sunday.sh Or add after the command ;sleep 1;clear to clear the screen after one second.
- o11c 3y agoThe 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
- deleted 3y ago[deleted]
- jcul 3y agoMaybe just touch a file somewhere in /tmp or /run or somewhere and do if [ -f $file ]; then touch $file ... If you never reboot could set up a cron job to delete it. Or store a counter in the file and output each time it reaches x % N. Might be susceptible to race conditions, so could wrap it in a flock or something...