Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Allow slash in alternation patterns in limited cases?
- X-seq: zsh-workers 38266
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: Allow slash in alternation patterns in limited cases?
- Date: Sun, 10 Apr 2016 15:11:05 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=Y8GpTYvv/qkf3CBtccKZw49dk6UdOmbEUECrhBCu0Zk=; b=Gd2UpoHJWZOJeBUdN1V6Ud6aGcnLO5oVUfX40xFnsIsAYSp7uaoAtAp5hbIdQbX6nJ wxCB36Qack3NaKpSVGg7IAgv2oVVu19yrzje52ryaeuS0TIBMYCZJAQ8SROJaanlLU8J krlUyOu8ojdsEd57YSZR3im6a8I5RhDyJcyKApE+H0WzS4MXbVe5/cUQKDtTnyUQljO+ tmkloTMZ/VVXzE6oySHWUOKopASjVnwG9noF6w7VNQq0o/K3kBmbVE40Sz0WvEPRqx4R aJQ/DMKdSHD8bFubX9suV68fsrl113hlI1wDSAyNUfVYq7zrjfmG2ix59BirKJ7D08/f HkwQ==
- In-reply-to: <CAHYJk3TY5kU0fXDkk2iO7kRJhhMTS1f4a9Am1ueN4wCXOQ7Hsg@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHYJk3TY5kU0fXDkk2iO7kRJhhMTS1f4a9Am1ueN4wCXOQ7Hsg@mail.gmail.com>
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