From: Mikael Magnusson <mikachu@gmail.com>
To: Zach Riggle <zachriggle@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Compound Glob Specifiers
Date: Tue, 9 Nov 2021 08:52:39 +0100 [thread overview]
Message-ID: <CAHYJk3SMpihVGL3xoC7CgwQi8VDGMTs7=05ibsKMJRubsMdpzg@mail.gmail.com> (raw)
In-Reply-To: <CAMP9c5kG4cR7QxMu93cLeZn_4BmZht=toAijxj4GvnKbYMm5Gw@mail.gmail.com>
On 11/9/21, Zach Riggle <zachriggle@gmail.com> wrote:
> I expect this is a case of "you're holding it wrong", but I figure it's
> worth asking what the right way to do this is...
>
> I want to glob the equivalent of */*/somefile (not **/foo, specifically two
> directories deep).
>
> However, I do NOT want the glob to match if any of the directory components
> are a symlink.
>
> *(/) is the glob specifier for directories [1]
>
> It would then follow that *(/)/*(/)/somefile would match dir/dir/somefile
> and not dir/link/somefile.
>
> This is not the case -- even *(/)/ (i.e. appending a trailing slash to all
> directories) do not work out-of-the-box as one might expect.
>
> I've read through 14.8 Filename Generation [2] as best I can (my favorite
> hack being the NTREF=reffile bit) but haven't found anything that suggests
> how one might do this.
You can do this explicitly by
one=( *(/N) )
two=( $^one/*(/N) )
result=( $^two/somefile(N) )
or more cryptically
() { () { cmd $^@/somefile(N) } $^@/*(/N) } *(/N)
(this will run cmd even if there were no matches)
--
Mikael Magnusson
prev parent reply other threads:[~2021-11-09 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-08 23:03 Zach Riggle
2021-11-09 3:04 ` Lawrence Velázquez
2021-11-09 3:30 ` Bart Schaefer
2021-11-09 7:52 ` Mikael Magnusson [this message]
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='CAHYJk3SMpihVGL3xoC7CgwQi8VDGMTs7=05ibsKMJRubsMdpzg@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=zachriggle@gmail.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).