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

Re: exclude users in watch variable?



Andy Spiegl wrote on Wed, Feb 11, 2015 at 12:46:55 +0100:
> > For an alternative I'd suggest writing a custom precmd.
> Thanks for the suggestion.  I started to think about how to implement
> this but came to the conclusion that my zsh knowledge is not good
> enough for this. :-(  I could write a perl script but in precmd ... No!
> 
> Could one of you zsh cracks give me a good start, please?
> 

Like this? ---

    autoload -Uz add-zsh-hook
    old=
    precmd_who() {
      local new="$(who)"$'\n' # add newline to reduce spurious diffs
      if [[ -n $old ]] ; then diff =(<<<$old) =(<<<$new) ; fi
      old=$new
    }
    add-zsh-hook precmd precmd_who

If 'who' doesn't run quickly in your environment you'll notice delays
before shell prompts are drawn.  The variable 'old' is in the global
namespace, you should probably name it something more unique to avoid
name collisions.

Daniel



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