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

Re: How to overcome the (a/b/c…)(N) pattern limitation?



On Sat, 18 Apr 2020 at 16:31, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
wrote:

> On Sat, Apr 18, 2020 at 4:08 PM Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
> > pick="(/tmp/gh|./gh)"
> > list=( ${(M)~pick##/*}(DN) )
>
> I'll simplify:
>
>   pick="(/tmp/gh|./gh)"
>   list=( $~pick )
>
> This doesn't work because $pick contains slashes within parentheses.
> This isn't allowed in file generation (with one exception). From the
> docs:
>
>   (...)
>
>   Matches the enclosed pattern. [...]
> …
>

Yes, but as I wrote, such patterns are useful, good ones and I'm looking
for an alternative form for them.

Also note that ##/* in your example is applied before file generation.
> The effect of the complete example is thus equivalent to this:
>
>   pick="(/tmp/gh|./gh)"
>   tmp=${(M)pick##/*}
>   list=( ${~tmp}(DN) )
>

Yes, I simplified the case again, the complete example is:

list=( ${(M)~ZINIT_ICE[pick]##/*}(DN)
$local_dir/$dirname/${~ZINIT_ICE[pick]##/*}(DN.) )

It matches either the absolute path given in pick, or applies it inside the
local directory.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org


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