zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: exclude users in watch variable?
Date: Wed, 11 Feb 2015 12:26:30 +0000	[thread overview]
Message-ID: <20150211122630.619e332c@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20150204174605.GA14529@spiegl.de>

On Wed, 4 Feb 2015 18:46:06 +0100
Andy Spiegl <zsh.Andy@spiegl.de> wrote:
> "watch=( notme )" excludes myself but is there a way to exclude other
> usernames?
> 
> I was trying "watch=( notme ^user1 ^user2 )" but I am expecting too
> much, right? 

Patterns are easy to add, we might as well do it.  I can't see how this
could be problematic since user names tty names and host names can't
contain pattern characters.

Note you'll need to do it the way suggested in the example: the list
you've got won't work because you're looking for an "or" of 'anyone apart
from me', 'anyone apart from user1', 'anyone apart from user2'.  In
fact, you can basically only use one negative in the list since "or"ing
negatives isn't useful.  I'm not proposing to change this since there
isn't a convenient alternative behaviour.

pws

diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index ee7c054..273be21 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -1472,15 +1472,27 @@ vindex(watch)
 vindex(WATCH)
 item(tt(watch) <S> <Z> (tt(WATCH) <S>))(
 An array (colon-separated list) of login/logout events to report.
+
 If it contains the single word `tt(all)', then all login/logout events
 are reported.  If it contains the single word `tt(notme)', then all
 events are reported as with `tt(all)' except tt($USERNAME).
+
 An entry in this list may consist of a username,
 an `tt(@)' followed by a remote hostname,
-and a `tt(%)' followed by a line (tty).
+and a `tt(%)' followed by a line (tty).  Any of these may
+be a pattern (be sure to quote this during the assignment to
+tt(watch) so that it does not immediately perform file generation);
+the setting of the tt(EXTENDED_GLOB) option is respected.
 Any or all of these components may be present in an entry;
 if a login/logout event matches all of them,
 it is reported.
+
+For example, with the tt(EXTENDED_GLOB) option set, the following:
+
+example(watch=('^(pws|barts)'))
+
+causes reports for activity assoicated with any user other than tt(pws)
+or tt(barts).
 )
 vindex(WATCHFMT)
 item(tt(WATCHFMT))(
diff --git a/Src/watch.c b/Src/watch.c
index 8dea0b4..fe409f9 100644
--- a/Src/watch.c
+++ b/Src/watch.c
@@ -372,6 +372,27 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
     return fmt;
 }
 
+/* See if the watch entry matches */
+
+static int
+watchlog_match(char *teststr, char *actual, int len)
+{
+    int ret = 0;
+    Patprog pprog;
+    char *str = dupstring(teststr);
+
+    tokenize(str);
+
+    if ((pprog = patcompile(str, PAT_STATIC, 0))) {
+	queue_signals();
+	if (pattry(pprog, actual))
+	    ret = 1;
+	unqueue_signals();
+    } else if (!strncmp(actual, teststr, len))
+	ret = 1;
+    return ret;
+}
+
 /* check the List for login/logouts */
 
 /**/
@@ -400,7 +421,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 	    for (vv = v; *vv && *vv != '@' && *vv != '%'; vv++);
 	    sav = *vv;
 	    *vv = '\0';
-	    if (strncmp(u->ut_name, v, sizeof(u->ut_name)))
+	    if (!watchlog_match(v, u->ut_name, sizeof(u->ut_name)))
 		bad = 1;
 	    *vv = sav;
 	    v = vv;
@@ -410,7 +431,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 		for (vv = ++v; *vv && *vv != '@'; vv++);
 		sav = *vv;
 		*vv = '\0';
-		if (strncmp(u->ut_line, v, sizeof(u->ut_line)))
+		if (!watchlog_match(v, u->ut_line, sizeof(u->ut_line)))
 		    bad = 1;
 		*vv = sav;
 		v = vv;
@@ -420,7 +441,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
 		for (vv = ++v; *vv && *vv != '%'; vv++);
 		sav = *vv;
 		*vv = '\0';
-		if (strncmp(u->ut_host, v, strlen(v)))
+		if (!watchlog_match(v, u->ut_host, strlen(v)))
 		    bad = 1;
 		*vv = sav;
 		v = vv;



  parent reply	other threads:[~2015-02-11 12:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-04 17:46 Andy Spiegl
2015-02-10 19:28 ` Andy Spiegl
2015-02-10 21:45   ` Daniel Shahaf
2015-02-11 11:46     ` Andy Spiegl
2015-02-11 16:56       ` Daniel Shahaf
2015-02-12  5:22         ` Bart Schaefer
2015-02-11 12:26 ` Peter Stephenson [this message]
2015-02-11 15:16   ` Andy Spiegl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150211122630.619e332c@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).