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

Re: Globbing feature suggestion

Oops -- meant to follow-up to the list -- still learning my way around
Gnus :-)

Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:

> [zsh-workers copied]
> On Dec 13, 9:13pm, Jonathan Hankins wrote:
> }
> } >  -nogroup is the glob qualifier (e['stat -s -A reply +gid $REPLY;
> } > reply=(${${(M)reply:#<->}/<->/$REPLY})'])
> }  This doesn't work for me -- stat -s returns '???' when there is no
> } pw/grent for the the u/gid.
> Urk.  Sorry about that; I don't actually *have* any files with unknown
> uid/gid on my system, but I had assumed "stat" would return the
> numeric ID in the absence of a name, the way "ls -l" does.

I didn't either, but it gave me the chance to discover that chown(1)
on my linux box works if you specify a numeric ID, even if there is no
corresponding pw/grent.  Who would have guessed?

> In fact I think it's pretty darn useless to return '???' for all
> unknown IDs, as if they were equivalent.  Would anyone seriously
> object if that were changed?

I thought the same when I saw it.  I guess it _does_ give you a way to
tell when a user or group does _not_ exist.

> } It works if I change it to:
> } 
> }   -nogroup is the glob qualifier (e['stat -s -A reply +gid $REPLY;
> } reply=(${${(M)reply:#???}/???/$REPLY})'])
> As that's written, ??? is a pattern matching any three characters, so
> if you have any 3-letter usernames on your system, that would
> improperly include them.  You need \?\?\? instead.

Yeah, I had the backslashes at first, then I tried without it and it
still matched, so my brain shut off for a minute and I forgot that
(e::) re-evaluates its argument.

Speaking of nearly-useless globbing, here is a function to glob all
files that are group-owned by _any_ of your groups, including primary
(login) GID.  Contrast with (G):

# $Id: is_gid_file,v 1.3 2005/12/14 00:21:38 jhankins Exp $

# Compare gid of file specified in $REPLY to all of user's groups.  Use like:
#   % print *(+cmp_gid)
# to list all files group-owned by _any_ of user's groups.  Compare to:
#   % print *(G)
# which only lists files owned by user's primary group.

emulate -L zsh
zmodload -i zsh/stat

typeset -ag _gids

if [[ $#_gids < 1 ]]; then
    _gids=($(id -G))

[[ -n ${(M)_gids:#$(stat +gid -- $REPLY)} ]]



-Jonathan Hankins

|Jonathan Hankins  | 		       	 jonathan-hankins@xxxxxxxxxxxxxx |

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