Hacker News new | past | comments | ask | show | jobs | submit login

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


Maybe 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...


You 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: