* exclude users in watch variable? @ 2015-02-04 17:46 Andy Spiegl 2015-02-10 19:28 ` Andy Spiegl 2015-02-11 12:26 ` Peter Stephenson 0 siblings, 2 replies; 8+ messages in thread From: Andy Spiegl @ 2015-02-04 17:46 UTC (permalink / raw) To: zsh-users "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? Thanks! Andy. -- Some people will never learn anything because they understand everything too soon. (Alexander Pope) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-04 17:46 exclude users in watch variable? Andy Spiegl @ 2015-02-10 19:28 ` Andy Spiegl 2015-02-10 21:45 ` Daniel Shahaf 2015-02-11 12:26 ` Peter Stephenson 1 sibling, 1 reply; 8+ messages in thread From: Andy Spiegl @ 2015-02-10 19:28 UTC (permalink / raw) To: zsh-users I suppose no answer by noone means that it's impossible, right? Thanks, Andy. On 2015-02-04, 18:46, Andy Spiegl 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? -- me@condor:~> find . -name home There's no place like home. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-10 19:28 ` Andy Spiegl @ 2015-02-10 21:45 ` Daniel Shahaf 2015-02-11 11:46 ` Andy Spiegl 0 siblings, 1 reply; 8+ messages in thread From: Daniel Shahaf @ 2015-02-10 21:45 UTC (permalink / raw) To: zsh-users $watch does not support patterns. For an alternative I'd suggest writing a custom precmd. Maybe someone else has a better idea. (Incidentally, if $watch did support patterns, you'd have needed to (a) quote the ^ so it isn't interpreted as filename generation, (b) consolidate the two negative patterns as '^(user1|user2)' because otherwise between them they'd match everything. Cheers, Daniel Andy Spiegl wrote on Tue, Feb 10, 2015 at 20:28:57 +0100: > I suppose no answer by noone means that it's impossible, right? > Thanks, > Andy. > > On 2015-02-04, 18:46, Andy Spiegl 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? > > -- > me@condor:~> find . -name home > There's no place like home. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-10 21:45 ` Daniel Shahaf @ 2015-02-11 11:46 ` Andy Spiegl 2015-02-11 16:56 ` Daniel Shahaf 0 siblings, 1 reply; 8+ messages in thread From: Andy Spiegl @ 2015-02-11 11:46 UTC (permalink / raw) To: zsh-users > 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? Thanks! Andy. -- The opossum is a very sophisticated animal. It doesn't even get up until 5 or 6 pm. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-11 11:46 ` Andy Spiegl @ 2015-02-11 16:56 ` Daniel Shahaf 2015-02-12 5:22 ` Bart Schaefer 0 siblings, 1 reply; 8+ messages in thread From: Daniel Shahaf @ 2015-02-11 16:56 UTC (permalink / raw) To: zsh-users 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 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-11 16:56 ` Daniel Shahaf @ 2015-02-12 5:22 ` Bart Schaefer 0 siblings, 0 replies; 8+ messages in thread From: Bart Schaefer @ 2015-02-12 5:22 UTC (permalink / raw) To: zsh-users On Feb 11, 4:56pm, Daniel Shahaf wrote: } } 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 This seems like an ideal application for the delayed-update trick. typeset -gH update_prompt_fd old_who typeset -g normal_prompt='%m $ ' # watch_who expects a single argument that looks like "$(who)" and # compares it to the argument passed to the previous watch_who call watch_who() { local new="$1"$'\n' if [[ -n $old_who ]] then local who_prompt="$(diff =(<<<$old_who) =(<<<$new))" if [[ -n $who_prompt ]] then PROMPT="$who_prompt"$'\n'"$normal_prompt" fi fi old_who="$new" } # update_who is a ZLE I/O handler, which reads output from a background # process (expected to be "who"), passes it through watch_who, and then # deletes the handler instance and updates the prompt update_who () { watch_who "$(read -d '' -rE -u$1)" update_prompt_fd=0 zle -F $1 exec {1}>&- zle reset-prompt } zle -N update_who # precmd_who sets up the update_who handler if it is available, and # otherwise runs watch_who directly to put the diffs into the prompt. # If your "who" is fast, simply skip the "zle -N" above. precmd_who() { PROMPT="$normal_prompt" if zle -l update_who then (( update_prompt_fd )) && zle -F $update_prompt_fd >/dev/null exec {update_prompt_fd}<<( who ) zle -F -w $update_prompt_fd update_who else watch_who "$(who)" fi } autoload -Uz add-zsh-hook add-zsh-hook precmd precmd_who ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-04 17:46 exclude users in watch variable? Andy Spiegl 2015-02-10 19:28 ` Andy Spiegl @ 2015-02-11 12:26 ` Peter Stephenson 2015-02-11 15:16 ` Andy Spiegl 1 sibling, 1 reply; 8+ messages in thread From: Peter Stephenson @ 2015-02-11 12:26 UTC (permalink / raw) To: zsh-users 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; ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: exclude users in watch variable? 2015-02-11 12:26 ` Peter Stephenson @ 2015-02-11 15:16 ` Andy Spiegl 0 siblings, 0 replies; 8+ messages in thread From: Andy Spiegl @ 2015-02-11 15:16 UTC (permalink / raw) To: zsh-users > Patterns are easy to add, we might as well do it. Very cool, thanks! > Note you'll need to do it the way suggested in the example: Yes, sounds very logical. When typing my example I was thinking on / proposing a much easier level. :-) I assume this won't make it into the next Debian release, right? I'm using zsh on too many machines to manually install this patch without big efforts. Thanks, Andy. -- All the President is, is a glorified public relations man who spends his time flattering, kissing and kicking people to get them to do what they are supposed to do anyway. (Harry S. Truman) ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2015-02-12 5:22 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-02-04 17:46 exclude users in watch variable? 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 2015-02-11 15:16 ` Andy Spiegl
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).