Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Re: (Y) modifier: up to N matches?



Oliver Kiddle wrote on Fri, Jun 06, 2014 at 01:24:45 +0200:
> Considering uses of the new (Y) modifier as I've understood it: I
> commonly use (../)# to find the top-level of something. For example
> (../)#.git(:h) will find the top of a git checkout. It'd be useful if
> this would stop searching after the first match which should be the
> one that involves going up as few directories as possible.

It does:

    % setopt extendedglob
    % cd $(mktemp -d)
    % mkdir -p foo A/foo A/B
    % cd A/B
    % echo (../)#foo(:A:h:t)
    A tmp.Ykz8jNBvJo
    % echo (../)#foo(Y1:A:h:t)
    A

(Also: 'git rev-parse --show-toplevel')

> I'm also inclined to think that with downward globs that you'd want it
> to find the nearest match so checking files before directories.

That's the current behaviour:

    % mkdir -p A/B/foo A/foo
    % echo **/foo(Y1)
    A/foo

It may be worthwhile adding a unit test for this to Test/D02glob to
ensure this behaviour doesn't change.

Daniel

>



Messages sorted by: Reverse Date, Date, Thread, Author