showLatest 10 is
(om[1,10]) at the end of the pattern. These are glob qualifiers;
om sorts by modification time (youngest first) and
[1,10] selects the first 10 matches.
find src -type f -iname \*.py is
print -lr src/**/(#i)*.py(D.) (you need to run
setopt extended_glob first, put that in your
The globbing flag
. filters regular files only,
D includes hidden files and files in hidden directories like the
find version would.
(#i) is a globbing flag that makes the remainder of the pattern case-insensitive.
print -lr prints its arguments, one per line (make that
print -lr -- if the first argument may begin with a dash). Combining the two, to get the most recent files:
print -lr src/**/(#i)*.py(D.om[1,10])
which in practice you can shorten to
print -lr src/**/*.py(om[1,10]).
In zsh, you probably won't need this because you can sort the list of files when you get it, at least if they're all coming from a single pattern. Here's a way to implement
showLatest in zsh that works with an arbitrary list of files. Unfortunately, the
om glob qualifier can only be applied to a single pattern, and a single pattern can only match files in a single directory or tree. A trick to bypass this is to use the
+) glob qualifier to inject an arbitrary list into a match result. Then apply an
o glob qualifier to perform the sorting; built-in qualifiers don't act on the result of the
+ rewrite, but custom ones (
o+) do (as of zsh 5.0.5).
print -lr .(e\''reply=($files)'\'noe\''stat -A REPLY +mtime -- $REPLY'\')