zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: difference between ~ & ^ negation
Date: Fri, 03 Jan 2014 13:43:26 -0800	[thread overview]
Message-ID: <140103134326.ZM11500@torch.brasslantern.com> (raw)
In-Reply-To: <20140103201056.1bb2dc32@pws-pc.ntlworld.com>

On Jan 3,  8:10pm, Peter Stephenson wrote:
} 
} Corrections I spotted myself before anyone else picks nits.

Sadly, here come some nits anyway.

} +  For matching files by globbing, mytt(~) is the only globbing
} +  operator to have a lower precedence than mytt(/).  In other words,
} +  when you have mytt(/a/path/to/match~/a/path/not/to/match) the mytt(~)
} +  considers what's before and what's after as complete paths to file names.

In my first response on this thread, I struggled mightily with how to
explain exactly how the before/after patterns are applied.  The phrase
"complete paths to file names" might be considered to mean that the
paths must start from the root (which your example further suggests),
but in fact they're not "complete" paths.  For purposes of the pattern
before the tilde, it matches ordinary path references which unless begun
with a slash are relative to $PWD.  For purposes of the pattern after
the tilde, it matches strings, which merely happen to be [parts of] the
names of things derived from the paths matched by the before part.

} +  You can put any other pattern characters in the expressions before and
} +  after the mytt(~), but note that the pattern after the tt(~) is really
} +  just a single pattern to match against every file found.

This is what I mean ... it doesn't match against the *file* (so, e.g.,
qualifiers such as (@) or (/) don't matter) -- it matches against the
*path name* of the file.

} +  If that's confusing, you can think of how mytt(~) works like this:
} +  take the pattern on the left, use it as normal to make a list of
} +  files, then for each file found see if it matches the pattern on the
} +  right and if it does take that file out of the list.

Except thinking of it that way is misleading, because the other hard-
to-grasp bit of this is that the after-pattern is matched against the
name of each file AS IT IS FOUND by matching the before-pattern, *not*
as a filter over the list of names after they are all found.  That
means that it's applied *before* any glob qualifiers including (e:...:)
or (+...).

} +  if you're matching files by globbing note you can't put mytt(/)s
} +  inside the parentheses since the groups can't stretch across multiple
} +  directories.  (You can do that, of course, whenever the character
} +  mytt(/) isn't special.)

Which means you can only exclude multi-segment paths by using ~pat/tern
at the very end of a glob.  Another gotcha with the parenthesizing bit
is that ^ is also a qualifier, so (^foo) at the end of glob is parsed
as a qualifier unless you add more parens or have NO_BARE_GLOB_QUAL.


  reply	other threads:[~2014-01-03 21:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-01 15:28 zzapper
2014-01-01 21:44 ` Bart Schaefer
2014-01-02 21:01   ` Peter Stephenson
2014-01-02 21:36     ` Bart Schaefer
2014-01-02 22:14       ` Peter Stephenson
2014-01-03  1:55       ` Mikael Magnusson
2014-01-03  7:37         ` Bart Schaefer
2014-01-03 19:48           ` Peter Stephenson
2014-01-03 20:10             ` Peter Stephenson
2014-01-03 21:43               ` Bart Schaefer [this message]
2014-01-04 21:11                 ` zzapper
2014-01-05 10:01                   ` Eike von Seggern
     [not found] ` <8lp61n01B02mHnv01lp8uc>
2014-01-03 20:56   ` how to shut off auto spell steve
2014-01-03 21:52     ` Bart Schaefer
     [not found]     ` <9ZwH1n01Z02mHnv01ZwLWZ>
2014-01-03 22:07       ` steve

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=140103134326.ZM11500@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@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).