zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: (#cN,M) error, %? doesn't glob
Date: Fri, 24 Jun 2011 04:00:43 +0200	[thread overview]
Message-ID: <BANLkTineRk+V1C8osSn0j5OhEbgrgDwrug@mail.gmail.com> (raw)

Someone asked on irc if there was a way to limit **/foo to 2 levels,
and I explained how **/ is short for (*/)# so he should be able to use
(*/)(#c,2), but that produces a bad pattern error. The manual says
that "The flag (#cN,M) can be used anywhere that the # or ## operators
can be used".

(*/)# is special-cased together with **/ in parsecomplist(), so it is
nontrivial to make it parse (#c) stuff, so here's an update for the
documentation to add an exception. Looking further, not just the
parsing but the whole scanner knows about this construct and hardcodes
0/1 or more dirs behaviour, so it would be a lot of work to change.

--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1992,7 +1992,8 @@ point on.
 )
 item(tt(c)var(N)tt(,)var(M))(
 The flag tt(LPAR()#c)var(N)tt(,)var(M)tt(RPAR()) can be used anywhere
-that the tt(#) or tt(##) operators can be used; it cannot be combined
+that the tt(#) or tt(##) operators can be used except in the expressions
+`tt((*/)#)' and `tt((*/)##)'; it cannot be combined
 with other globbing flags and a bad pattern error occurs if it is
 misplaced.  It is equivalent to the form tt({)var(N)tt(,)var(M)tt(}) in
 regular expressions.  The previous character or group is required to


While looking at Src/glob.c I also noticed that ? is ignored for
globbing if it is preceded by a % at the start of a string, is that
documented anywhere? bash doesn't have this behaviour, and emulate sh
obviously doesn't help.
    /* If % is immediately followed by ?, then that ? is     *
     * not treated as a wildcard.  This is so you don't have *
     * to escape job references such as %?foo.               */
    if (str[0] == '%' && str[1] == Quest)
	str[1] = '?';
I would argue that if someone is too lazy to escape their job
references they should just setopt nonomatch. I can imagine files like
that existing if you downloaded some nonlatin filenames via http and
they were saved percent-escaped, then you might want to find such
files with %??%* or something, maybe? I know that at least I would be
very confused if zsh then told me "no matches found", viz,
% touch %ab%de
% echo %??%*
zsh: no matches found: %??%*
% echo (#)%??%*
%ab%de

I sort of feel like an explicit option for this would be a bit awkward.

-- 
Mikael Magnusson


             reply	other threads:[~2011-06-24  2:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24  2:00 Mikael Magnusson [this message]
2011-06-24  4:12 ` Bart Schaefer
2011-08-14  7:44   ` Mikael Magnusson
2011-08-14 22:56     ` Bart Schaefer
2011-08-14 23:21       ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTineRk+V1C8osSn0j5OhEbgrgDwrug@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).