The best kittens, technology, and video games blog in the world.

Monday, May 09, 2016

autoreporter gem

The latest in kitten eyeware. by shadow planet from flickr (CC-NC-ND)
Many times I wanted to display status of something in terminal tab. The obvious way to do so would be something like:

while true
  system "clear" # Clear the screen
  system "rake status" # run command reporting status
  sleep 60

Which is nearly ruby -e one-liner with some golfing.

This is good enough if rake status is close to instantaneous. Unfortunately if it does anything nontrivial - like checking with external network service, searching filesystem and so on - then most of the time when you switch to status tab you'll be seeing empty or incomplete screen instead of probably much more useful previous minute's report.

And so I created autoreporter script, which I now packaged into a gem of the same name. To use it open terminal tab and run autoreporter rake status or whatever you want it to run to get status. It will manage screen refreshes, STDERR redirection and such, and has command line switches for things like delay and verbosity.

I used it for over a year now. Initially I thought it will need fancy features like multiple independent report sources, watching file changes, forcing refresh by some keyboard shortcut, and so on, but in reality I never needed any of that.

Before I wrote autoreporter I tried to use rerun but lack of output buffering really kills it.

No comments: