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

Re: "Watch" function?



Richard Coleman writes:

> > Instead of/in addition to being able to specify a format string for the
> > "watch" facility, how hard would it be to have a special function which, if
> > defined, would be called whenever the "watch" facility "saw" someone
> > login/logout?  (Akin to precmd(), periodic(), chpwd(), etc.)
> 
> I meant to reply to this earlier but got sidetracked.  Having zsh execute
> a shell function at this point is easy.  The hard part is passing all the
> information that you can access in WATCHFMT to this shell function.  We
> would probably have to create more special parameters to do this.  I'm
> not sure if it is worth it.

I've been thinking about this too. The obvious solution is to pass the
data in in $1 etc, but this is perhaps a little ugly. Another
possibility is to define local variables for the duration of the call,
with meaningful names for the parameters being passed in. A little
nicer, although I never found "magically appearing variables" very
clean....

Perhaps a builtin to return system status. This probably sounds like
the most work, but it's perhaps (???) cleaner than the above
two... eg. The default "watch" function could simply contain:

echo "`zshstat user` has `zshstat action` on `zshstat tty` from
`zshstat host`" >&2

Or, for the sake of more efficient default functions:

zshstat %user has %action on %tty from %host >&2

This has the advantage of lazy evaluation of the information for
WATCHFMT, TIMEFMT, whatever, plus _naming_ the data, instead of
indexing the parameters, plus fitting cleanly in with how you expect
the shell to work (less magic), and gets rid of that purpose built
code in zsh to handle special cases like WATCHFMT, gets rid of a few
more special shell variables. All it adds is this bizarre builtin, the
behaviour of which needs to be decided...

Dave.



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