thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

hwatch

β€’ 297 words β€’ 2 min β€’ updated

hwatch:

hwatch: alternative watch command with history, diff view, JSONL logging, and change hooks. since 2018.

Or, even better, from its man page hwatch(1):

hwatch is like watch command, repeatedly executes a command and displays its output. However, the output results can be scrolled and displayed. In addition, the difference of the execution result is recorded with the time stamp, and it can be checked later. When checking, it is also possible to display the diff with the previous difference together.

This is the first project I’ve ever stumbled upon that (i) is written in Rust, and (ii) doesn’t brag about being written in Rust. Am I having a dream? Not kidding, there’s not a single mention of Rust in its README.md.

As usual, it is available via your favorite package manager.

I particularly like:

that records the result of command execution, can display it history and diffs […]

A simple way to test it:

shell
% hwatch git status

Then make a silly change like:

shell
% touch foo

It behaves just like vanilla watch(1):

watch runs command repeatedly, displaying its output and errors (the first screenful). This allows you to watch the program output change over time. By default, command is run every 2 seconds and watch will run until interrupted. A header informs of the start and running time of command as well as its exit code.

…plus a few goodies such as history tracking.

h opens a pop-up with in-app keyboard shortcuts1.

--aftercommand (hook) is also interesting:

shell
% hwatch --aftercommand '/usr/bin/afplay /System/Library/Sounds/Glass.aiff' git st

…makes a chime sound upon each diff2.

A poor man’s stopwatch:

shell
% hwatch --aftercommand '/usr/bin/afplay /System/Library/Sounds/Glass.aiff' --interval 1 date

  1. Why not ?? :( ↩︎

  2. There’s also a native --beep option but it did not work in my terminal. ↩︎