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

Re: Allow slash in alternation patterns in limited cases?



On Apr 10, 10:36pm, Mikael Magnusson wrote:
}
} /path/(to/file|or/another/file) # nope, too hard
} (/path/to/a/dir/*|/path/to/some/other/files/*) # can we allow this?

My gut feeling is that this is close to impossible.  In fact your first
example might actually be easier than your second, because there are no
pattern characters within the alternation.  Similarly I think
    (/path/to/a/dir|/path/to/some/other/files)/*
would be easier than the case where the wildcard is inside the parens,
because an opendir() might be forced on each fixed path.

} If not, would it be possible to invent some new syntax to "paste" two
} or more globs together so that a single set of glob
} quals/sorts/flags/subscripts could apply to it?

Syntactically, this would probably work best as a parameter expansion
flag, which accepts a glob qualifier and applies it to every value in
the (array) expansion.  I'm not sure if there are any letters left for
this; we've reserved (_:stuff:) for future use, so possibly something
like e.g. ${(_:#qom[1]:)array} would work.  I insert the #q so that
other stuff in (_:stuff:) might still be adopted in future.

(Also is the above equivalent to ${${(_:#qom:)array}[1]} and if so do
we prohibit the qualifier subscripting in this form?)

Internally, to make this fly, the glob.c:zglob() function must be
factored apart into the bit that parses glob flags, the bit that makes
the call to scanner() [which would get called in a loop over the array
elements], and finally the bit that handles gf_sortlist and makes the
calls to insert_glob_match().

This is probably a significant effort because of the use of C globals
for glob state [although that might be easier since workers/38188].

Of course readability takes a major dive here as we're mating together
our two most cryptic bits of syntax into a single monster.  The only
other idea I have is to use a command form like

    zglob -q 'om[1]' $array

which to substitute-in place like a normal glob would need to be written

    echo $(zglob -q 'om[1]' $array)

which for efficiency would mean we implement the ksh-style non-fork of
builtins appearing in $(...), and now we're down another rabbit hole.



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