Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: monitor screen output




Am Montag, den 11. November 2024 um 17:45 schrieb Ray Andrews:
All:

Can zsh monitor screen output in a backgroundy sort of way?  Say I have several programs that might at some time or other output some message, can zsh keep an eye on the screen any time it is written to and detect that message and act upon it?

If you want it to be done natively in zsh you could probably use the zpty module (see zshmodules(1)):

Load the module:

  $ zmodload zsh/zpty

Start top in the background. That would be your program to monitor.
It will get the handle 'top'. You may start several programs with different handles:

  $ zpty top top

Read from the pseudo terminal into "var" until pattern "*mutt*" was found:

  $ zpty -r top var "*neomutt*"

Now Start neomutt in another shell. Above command should return after a couple seconds and $var should contain the top output including the matched text.

Cancel the background process if you are done:

  $ zpty -d top


Expect is probably the saner option to use.


Sebastian




Messages sorted by: Reverse Date, Date, Thread, Author