new journalizer, stare and better than homebrew

statico on 2005-08-20T14:20:19

Taking pudge's suggestion, I modified my use Perl; Journalizer application to use the SOAP API instead of the slightly-buggy WWW::UsePerl::Journal. Now I can write journal entries in spell-checked, minimal-syntax KwikiText and not worry that comments are disabled.

Speaking of tools, have you ever searched for a small utility, only to find in disbelief that no one has already written it, then written it yourself? The most memorable tool in my case is a utility I call "stare."

I'm sure we've needed to watch repeatedly the output of some command. Maybe it was the listing of a directory or some program that reports status information. In those cases, this might come to mind:

$ while true; do clear; some-command; sleep 1; done

The problem with the above is that the display flickers. "Okay," you might say, "so why not recreate it with Curses?" Well, fair reader, that's exactly what I did almost two-and-a-half years ago. I called it "stare" and used it as an excuse to learn the Curses module. I included two useful options: the ability to hide the header line and the number of seconds to refresh. With the exception of resizing the terminal, it mostly works.

I was recently in an environment where installing Perl modules was, at the time, not an option. Remembering that David uses something called "vis," I searched and found vis.c, an example from Unix Power Tools, 3rd ed.. I did have access to gcc so I began to use it, even though it has the terminal-resizing bug and a small hatred for certain argument combinations.

Now here's the kicker: I needed to abstract vis into another utility, which I called watchconf. A few minutes later, when I went to use my shiny new command, tab-completion caused me to blink:

$ watch
watch      watchconf

Eh? What is this watch you speak of?

$ man watch
NAME
     watch - execute a program peri-
     odically,    showing     output
     fullscreen

No way!

SYNOPSIS
     watch  [-dhvt]  [-n  ]
     [--differences[=cumulative]]
     [--help] [--interval=]
     [--no-title] [--version]  

NO!

DESCRIPTION
     watch  runs command repeatedly,
     displaying  its   output   (the
     first screenfull).  This allows
     you to watch the program output
     change  over time.

Yes, folks, this utility comes with the "procps" package, which is installed on Debian Sarge / Ubuntu Hoary by default, AFAIK. Not only has it been there all along, but it includes a "highlight differences" option and it can handle terminal resizing.

I'll sit here patiently and wait for the "told-you-so's."


Re:

Aristotle on 2005-08-21T03:52:40

Heh, yep. As soon as I saw while true ; clear I thought “doesn’t he know about watch?”

Amusing way to stumble over it by yourself, though. :-)

I'm much too lazy...

Purdy on 2005-08-22T13:12:51

I go through those myself, but I'm too lazy to write the code, so I usually just shelve the thought or work around it.

My last one is a 'blank' command, which will blank out a file, but leave it there (0 bytes) with the same privs, owners, etc. But there's prolly a easy workaround, like "echo '' > /path/to/file"

- Jason

told you so?

aripollak on 2005-09-07T23:06:28

I told you about this back when you wrote stare.