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

Re: Emulating 'locate'



[We should just go off and have our own little mailing list.]

On Oct 2, 12:17am, DervishD wrote:
}
} Well, I suppose that slashes must be
} matched explicitly (that is what ** is for...)

No, that is what **/ is for.  Each **/ (but not /**) triplet is replaced
by zero or more levels of hierarchy.  It's the trailing slash that makes
** magical; without it ** is just like *.

Actually to be entirely accurate, not _every_ **/ triplit is so replaced;
the **/ has to be the only thing in one level of hierarchy, i.e., it can't
be foo**/ either.

}     Let do 'locate ir2'. The list of output files is the same as
} 'locate ir3' (well, it outputs a couple of dirs more). But if I do
} 'print -l /**/*ir2*/**' I only get '/dir1/dir2/dir3' :((( In fact,
} adding more ** doesn't work: 'print /**/*ir2*/**/**' just outputs
} '/dir1/dir2/ /dir1/dir2/dir3/ /dir1/dir2/dir3'

That last should have done almost what you wanted, except the final *
is redundant.  I suspect you really did

    print /**/*ir2*/*/**
                   ^^^ Note only one star here
when you meant

    print /**/*ir2*/**/*

But that's still not sufficient, because it requires that *ir2* be only
an intervening directory and not the last file or directory in the path.
For that you have to use brace expansion, because you can't mix **/ and
any other form of alternation:

    print -l /**/*ir2*{,/**/*}

So "locate" would be e.g.

    locate() { print -l /**/*${^*}*{,/**/*} }

(You really ought to be sending these questions to -users, not -workers.)

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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