Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Globbing feature suggestion
- X-seq: zsh-users 9791
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: Globbing feature suggestion
- Date: Tue, 13 Dec 2005 04:16:49 +0000
- In-reply-to: <87irtt4uno.fsf@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <87irtt4uno.fsf@xxxxxxxxxxxxxxx>
On Dec 12, 8:07pm, Jonathan Hankins wrote:
}
} What if you could get the effect of find(1)'s "-nouser" and "-nogroup"
} (true for files whose numeric UID and GID have no corresponding entry
} in the passwd file)
This is computationally a fairly expensive operation, particularly if
"the passwd file" is an NIS map or the like. Zsh's (uID) and (gID)
qualifiers work by looking up the ID once in the appropriate map and
then comparing to the stat data of each file; to implement -nouser or
-nogroup you have to first get the stat data from the file and then
look that up in the map. You could get into various optimizations
like caching previously-seen IDs so as not to look them up again, but
that's a lot of code for what seems like a fringe feature.
My feeling is that if you're going to invoke something that costly,
you ought to be aware of it; the shell shouldn't hide it behind a two-
letter abbreviation. It's not obvious, but with "zmodload zsh/stat":
-nouser is the glob qualifier
(e['stat -s -A reply +uid $REPLY; reply=(${${(M)reply:#<->}/<->/$REPLY})'])
-nogroup is the glob qualifier
(e['stat -s -A reply +gid $REPLY; reply=(${${(M)reply:#<->}/<->/$REPLY})'])
You can use the function shorthand in 4.3.x:
function nouser {
stat -s -A reply +uid $REPLY
reply=(${${(M)reply:#<->}/<->/$REPLY})
}
print *(+nouser)
Only try that recursively on a deep directory tree, though, when prepared
to wait a while.
Tangentially, a more useful feature would be for (^e:...:) to match the
name when reply=(). Currently (^e:...:) is guaranteed never to match,
and instead you have to figure out how to invert the computation. If
(^e:...:) were so implemented, then -nouser would be shortened to
(^e['stat -s -A reply +uid $REPLY; reply=(${reply:#<->})'])
which is not a lot better, but a little.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author