zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: "Jörg Ziefle" <joerg.ziefle@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: Glob specifiers for intermediate path components
Date: Wed, 26 Nov 2014 19:00:23 +0100	[thread overview]
Message-ID: <CAHYJk3TOZpJKUDxczqkr2RYJbOkjjN4mqG=kcf9o=3j=843QEA@mail.gmail.com> (raw)
In-Reply-To: <CAO8h=njW+7we5z+_E8pCYKdCG3UGUqWEJAZpsaQTts25ENpOyw@mail.gmail.com>

On Wed, Nov 26, 2014 at 6:32 PM, Jörg Ziefle <joerg.ziefle@gmail.com> wrote:
> Suppose I have the following directory structure:
>
> $ mkdir a
> $ touch a/1
> $ ln -s a b
> $ ls -ld a b a/1
> drwxr-xr-x  3 jozi  staff  102 Nov 26 18:27 a
> -rw-r--r--  1 jozi  staff    0 Nov 26 18:27 a/1
> lrwxr-xr-x  1 jozi  staff    1 Nov 26 18:27 b -> a
>
> Globbing for files within directories, I get the file within the
> directory pointed by symlink b too:
>
> $ print -l */*(.)
> a/1
> b/1
>
> How can I restrict the globbing for the first directory level to
> directories only, excluding symlinks to directories? The obvious
> doesn't work:
>
> $ print -l *(/)/*(.)
> zsh: bad pattern: *(/)/*(.)
>
> More generally, how can I specify glob qualifiers for intermediate
> path components? In spirit:
>
> $ print -l a(...)/b(...)/c(...)/d(...)/e(...)/f(...)
>
> where (...) denotes glob qualifiers for the respective path components, or even:
>
> $ print -l {{a(...)/b(...)}/c(...)}

You can't, as such. There are at least two workarounds I can think of.

print -l a(/e:'REPLY=$REPLY/b(/)':)
(this one quickly gets messy to nest)

() { print -l $^@/b(/) } a(/)
() { () { print -l $^@/c(/) } $^@/b(/) } a(/)
You may need to add N in the glob quals here too, or intermediate
directories with no children would produce a glob error.

Note more specifically also that **/*(.) does not recurse through
symlinks to directories, ***/*(.) would.

-- 
Mikael Magnusson


  reply	other threads:[~2014-11-26 18:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-26 17:32 Jörg Ziefle
2014-11-26 18:00 ` Mikael Magnusson [this message]
2014-11-27  1:52   ` Bart Schaefer
2014-11-27  4:27     ` Jörg Ziefle
2014-11-27  5:46       ` Bart Schaefer

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='CAHYJk3TOZpJKUDxczqkr2RYJbOkjjN4mqG=kcf9o=3j=843QEA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=joerg.ziefle@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).