New shell_util to watch output in multiple tmux panes at once

I assume most of you are familiar with watch program. If not – it shows, periodically, output of a command.

I was missing similar functionality for tmux, especially when I have multiple windows/panes.

So I wrote tmux_watch_many.

How to use it?

Well, you run it like this:

=$ tmux_watch_many '^win[024]'

And it does it's magic.

It will, every 1 second (configurable):

  • scan all available panes
  • get their content, removing empty lines
  • get just n last lines, so that output will fit on screen
  • show it all on screen

Script will end (by default) if there are no panes matching given MATCHER.

Full help:

=$ tmux_watch_many -h
Syntax:
    tmux_watch_many [-a] [-f] [-s SKIP_MATCHER] [-m LINE_MATCHER] [-w WAIT_TIME] PANE_MATCHER
 
Description:
    Shows last non-empty lines of all matching panes.
    Optionally skips lines provided by SKIP_MATCHER, and filters to lines
    matching LINE_MATCHER.
 
Options:
    -a : Enables matching across all sessions, not only current.
    -f : Forever, don't stop when there are no matching panes.
    -s : Skip lines that match this regular expression (egrep style).
    -m : Show only lines matching this regular expression (egrep style),
         defaults to : >>[^[:space:]]<<
    -w : Wait given time between checks of terminal, defaults to 1 (second).
 
Arguments:
    PANE_MATCHER    : Regular expression (compatible with egrep), that will be
                      used to select panes that should be processed.  Without
                      -a, panes are listed only from current session, and have
                      format:
                      WINDOW_NAME.PANE_INDEX
                      With -a, panes are listed from all sessions, and have
                      format:
                      SESSION_NAME:WINDOW_NAME.PANE_INDEX