#command #watch #monitoring #command-output #execute-command #ansi-colors #real-time

app hwatch

A modern alternative to the watch command, records the differences in execution results and can check this differences at after

17 releases

new 0.3.12 Apr 7, 2024
0.3.11 Mar 4, 2024
0.3.10 Apr 15, 2023
0.3.9 Jan 4, 2023
0.1.6 Oct 31, 2021

#425 in Command line utilities

Download history 3/week @ 2024-02-15 21/week @ 2024-02-22 176/week @ 2024-02-29 69/week @ 2024-03-07 31/week @ 2024-03-14 16/week @ 2024-03-21 24/week @ 2024-03-28 167/week @ 2024-04-04

251 downloads per month

Custom license

5MB
4K SLoC

hwatch

hwatch - alternative watch command.

Description

hwatch is a alternative watch command. That records the result of command execution and can display it history and diffs.

Features

  • Can keep the history when the difference, occurs and check it later.
  • Can check the difference in the history. The display method can be changed in real time.
  • Can output the execution result as log (json format).
  • Support ANSI color code.
  • Execution result can be scroll.
  • Not only as a TUI application, but also to have the differences output as standard output.
  • If a difference occurs, you can have the specified command additionally executed.

Install

macOS (brew)

brew install hwatch

macOS (MacPorts)

sudo port install hwatch

Arch Linux (AUR)

paru -S hwatch

Cargo Install

cargo install hwatch

Usage

    $ hwatch --help
    A modern alternative to the watch command, records the differences in execution results and can check this differences at after.

    Usage: hwatch [OPTIONS] [command]...

    Arguments:
      [command]...

    Options:
      -b, --batch                         output exection results to stdout
      -B, --beep                          beep if command has a change result
          --mouse                         enable mouse wheel support. With this option, copying text with your terminal may be harder. Try holding the Shift key.
      -c, --color                         interpret ANSI color and style sequences
      -t, --no-title                      hide the UI on start. Use `t` to toggle it.
      -N, --line-number                   show line number
          --no-help-banner                hide the "Display help with h key" message
      -x, --exec                          Run the command directly, not through the shell. Much like the `-x` option of the watch command.
      -O, --diff-output-only              Display only the lines with differences during line diff and word diff.
      -A, --aftercommand <after_command>  Executes the specified command if the output changes. Information about changes is stored in json format in environment variable ${HWATCH_DATA}.
      -l, --logfile <logfile>             logging file
      -s, --shell <shell_command>         shell to use at runtime. can  also insert the command to the location specified by {COMMAND}. [default: "sh -c"]
      -n, --interval <interval>           seconds to wait between updates [default: 2]
          --tab-size <tab_size>           Specifying tab display size [default: 4]
      -d, --differences [<differences>]   highlight changes between updates [possible values: none, watch, line, word]
      -o, --output [<output>]             Select command output. [default: output] [possible values: output, stdout, stderr]
      -h, --help                          Print help
      -V, --version                       Print version

watch window keybind

Key Action
, move selected screen(history/watch).
select watch screen.
select history screen.
H show help window.
C toggle color.
D switch diff mode.
N switch line number display.
T toggle the UI (history pane and header).
Backspace toggle the history pane.
Q exit hwatch.
0 disable diff.
1 switch watch type diff.
2 switch line type diff.
3 switch word type diff.
O switch output mode(output->stdout->stderr).
Shift+O show only lines with differences(line/word diff mode only).
F1 only stdout print.
F2 only stderr print.
F3 print output.
+ increase interval.
- decrease interval.
Tab toggle select screen(history/watch).
/ filter history by string.
* filter history by regex.
Esc unfiltering.

Configuration

If you always want to use some command-line options, you can set them in the HWATCH environment variable. For example, if you use bash, you can add the following to your .bashrc:

export HWATCH="--no-title --color --no-help-banner"

Example

interval 10 second

Use the -n option to specify the command execution interval.

hwatch -n 3 command...

logging output

The command execution result can be output as a log in json format.

hwatch -n 3 -l hwatch_log.json command...

When you check the json log, you can easily check it by using this script.

Use shell function

If you want the shell function to be executed periodically, you can specify the shell command to be executed with -s as follows.

# bash
hwatch -n 3 -s 'bash -c "source ~/.bashrc"; {COMMAND}' command...

# zsh
hwatch -n 3 -s 'zsh -c "source ~/.zshrc"; {COMMAND}' command...

ANSI Color code

If you want to see output colored with ANSI color code, enable color mode.

To enable color mode, run hwatch with the -c option. Alternatively, you can enable / disable the color mode with the C key during execution.

hwatch -n 3 -c command...

diff view

To enable color mode, run hwatch with the -d option.

There are several "diff modes" available. Switching can be done with the D key.

hwatch -n 3 -d command...

watch diff

line diff

word diff

history filtering

You can filter history as a string with / key and as a regular expression with * key.

run batch mode

You can have command diffs output directly to stdout instead with -b option of getting them as a TUI app.

hwatch -b command...

Dependencies

~30–44MB
~757K SLoC