zsh-users
 help / color / mirror / code / Atom feed
* How to overcome the (a/b/c…)(N) pattern limitation?
@ 2020-04-18 12:49 Sebastian Gniazdowski
  2020-04-18 12:55 ` Roman Perepelitsa
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 12:49 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

Hi
I was trying to do: ls (/tmp/somedir/gh|./gh)(N) to obtain the error
message:

zsh: bad pattern: (/tmp/somedir/gh|./gh)(N)

I think that logically these are useful, good patterns and I wonder if
there's is a way to easily obtain a working equivalent of them?

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 12:49 How to overcome the (a/b/c…)(N) pattern limitation? Sebastian Gniazdowski
@ 2020-04-18 12:55 ` Roman Perepelitsa
  2020-04-18 13:41   ` Sebastian Gniazdowski
       [not found]   ` <CAKc7PVCJfCwUUrm5KXzzehxuX1JF=Bvwkh=m7we_TiCrtw_fhQ__30396.4317821496$1587217473$gmane$org@mail.gmail.com>
  0 siblings, 2 replies; 12+ messages in thread
From: Roman Perepelitsa @ 2020-04-18 12:55 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Sat, Apr 18, 2020 at 2:51 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> I was trying to do: ls (/tmp/somedir/gh|./gh)(N)

This should work:

  ls {/tmp/somedir/gh,./gh}(N)

Note that you'll get listing for the current directory if there are no matches.

Roman.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 12:55 ` Roman Perepelitsa
@ 2020-04-18 13:41   ` Sebastian Gniazdowski
  2020-04-18 13:45     ` Roman Perepelitsa
       [not found]   ` <CAKc7PVCJfCwUUrm5KXzzehxuX1JF=Bvwkh=m7we_TiCrtw_fhQ__30396.4317821496$1587217473$gmane$org@mail.gmail.com>
  1 sibling, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 13:41 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

On Sat, 18 Apr 2020 at 14:56, Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:

> On Sat, Apr 18, 2020 at 2:51 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> > I was trying to do: ls (/tmp/somedir/gh|./gh)(N)
>
> This should work:
>
>   ls {/tmp/somedir/gh,./gh}(N)
>
> Note that you'll get listing for the current directory if there are no
> matches.
>
> Roman.
>

I need the technique to be pattern-based – it is used in script in a
$~pattern way.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 13:41   ` Sebastian Gniazdowski
@ 2020-04-18 13:45     ` Roman Perepelitsa
  2020-04-18 14:07       ` Sebastian Gniazdowski
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2020-04-18 13:45 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Sat, Apr 18, 2020 at 3:43 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> I need the technique to be pattern-based – it is used in script in a $~pattern way.

The first example you posted was helpful because it was clear from it
what you want to achieve.

Can you post another example like that, one that cannot be fixed by
replacing (|) with {,}?

Roman.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 13:45     ` Roman Perepelitsa
@ 2020-04-18 14:07       ` Sebastian Gniazdowski
  2020-04-18 14:07         ` Sebastian Gniazdowski
  2020-04-18 14:31         ` Roman Perepelitsa
  0 siblings, 2 replies; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 14:07 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 695 bytes --]

On Sat, 18 Apr 2020 at 15:45, Roman Perepelitsa <roman.perepelitsa@gmail.com>
wrote:

> On Sat, Apr 18, 2020 at 3:43 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> > I need the technique to be pattern-based – it is used in script in a
> $~pattern way.
>
> The first example you posted was helpful because it was clear from it
> what you want to achieve.
>
> Can you post another example like that, one that cannot be fixed by
> replacing (|) with {,}?
>

pick="(/tmp/gh|./gh)"
list=( ${(M)~pick##/*}(DN) )

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 14:07       ` Sebastian Gniazdowski
@ 2020-04-18 14:07         ` Sebastian Gniazdowski
  2020-04-18 14:31         ` Roman Perepelitsa
  1 sibling, 0 replies; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 14:07 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

On Sat, 18 Apr 2020 at 16:07, Sebastian Gniazdowski <sgniazdowski@gmail.com>
wrote:

>
> pick="(/tmp/gh|./gh)"
> list=( ${(M)~pick##/*}(DN) )
>

PS. I would rather not use eval.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 14:07       ` Sebastian Gniazdowski
  2020-04-18 14:07         ` Sebastian Gniazdowski
@ 2020-04-18 14:31         ` Roman Perepelitsa
  2020-04-18 14:41           ` Sebastian Gniazdowski
  1 sibling, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2020-04-18 14:31 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Sat, Apr 18, 2020 at 4:08 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> 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. [...]

  Note that grouping cannot extend over multiple directories: it is
  an error to have a ‘/’ within a group (this only applies for
  patterns used in filename generation). There is one exception: a
  group of the form (pat/)# appearing as a complete path segment can
  match a sequence of directories. For example, foo/(a*/)#bar matches
  foo/bar, foo/any/bar, foo/any/anyother/bar, and so on.

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) )

Roman.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 14:31         ` Roman Perepelitsa
@ 2020-04-18 14:41           ` Sebastian Gniazdowski
  2020-04-18 20:00             ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 14:41 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1278 bytes --]

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

> On Sat, Apr 18, 2020 at 4:08 PM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 14:41           ` Sebastian Gniazdowski
@ 2020-04-18 20:00             ` Bart Schaefer
  2020-04-18 23:22               ` Sebastian Gniazdowski
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2020-04-18 20:00 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Roman Perepelitsa, Zsh Users

On Sat, Apr 18, 2020 at 5:51 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> I was trying to do: ls (/tmp/somedir/gh|./gh)(N) to obtain the error
> message:
>
> zsh: bad pattern: (/tmp/somedir/gh|./gh)(N)

Just making sure you don't mean that you were trying to obtain the
error message?  If you did mean that, what did you get instead?


On Sat, Apr 18, 2020 at 7:43 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Yes, but as I wrote, such patterns are useful, good ones and I'm looking
> for an alternative form for them.

In this case, "useful" collides directly with "practical" given the
semantics of "/" imposed by the underlying file system.

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

I'm a little puzzled about what the contents of ZINIT_ICE[pick] look
like.  Do you not want this to work for (.gh|/tmp/gh) as well as the
reverse?

If it's a simple list of alternatives without nested parens, you
should be able to do this:

list=( ${^~${(s:|:)ZINIT_ICE[pick]}//(#b)(#s)([^\/]*)/$local_dir\/$dirname\/$match(#q.)}(DN)
)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 20:00             ` Bart Schaefer
@ 2020-04-18 23:22               ` Sebastian Gniazdowski
  2020-04-19  0:02                 ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2020-04-18 23:22 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Roman Perepelitsa, Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2541 bytes --]

On Sat, 18 Apr 2020 at 22:00, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Sat, Apr 18, 2020 at 5:51 AM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > I was trying to do: ls (/tmp/somedir/gh|./gh)(N) to obtain the error
> > message:
> >
> > zsh: bad pattern: (/tmp/somedir/gh|./gh)(N)
>
> Just making sure you don't mean that you were trying to obtain the
> error message?  If you did mean that, what did you get instead?
>

No, I didn't want to obtain the error, so I guess that your first
impression was correct.


> On Sat, Apr 18, 2020 at 7:43 AM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > Yes, but as I wrote, such patterns are useful, good ones and I'm looking
> > for an alternative form for them.
>
> In this case, "useful" collides directly with "practical" given the
> semantics of "/" imposed by the underlying file system.
>

What do you mean? In the big, complete picture the user installs a
binary-release, GitHub plugin. It can come either from a deb/rpm file or
from a tar.gz. If it comes from deb (selected when the system has
dpkg-deb), then the binary will be located in plugin-dir/usr/bin/gh, if
from tarball then in plugin-dir/gh. So to match the file with the pick
ice-mod – Zinit's (formerly Zplugin) tool to select the binary that should
be added to PATH – an alternative (usr/bin/gh|gh) comes to mind. The issue
has resolved by using **/gh, however it puzzled me that such /-using
patterns aren't allowed. Mikachu has a patch allowing them, maybe it's
worth adding it to the upstream?:

http://comm.it.cx/cgit/zsh-cvs/commit/?h=mika&id=512bd3f23ea8b4170d88582521d417cdb247413a


> > list=( ${(M)~ZINIT_ICE[pick]##/*}(DN)
> > $local_dir/$dirname/${~ZINIT_ICE[pick]##/*}(DN.) )
>
> I'm a little puzzled about what the contents of ZINIT_ICE[pick] look
> like.  Do you not want this to work for (.gh|/tmp/gh) as well as the
> reverse?
>

It can be either an absolute path, like "$ZPFX/bin/something" (where ZPFX
is ~/.zinit/polaris by default) or an pattern that'll be applied inside the
plugin directory.

If it's a simple list of alternatives without nested parens, you
> should be able to do this:
>
> list=(
> ${^~${(s:|:)ZINIT_ICE[pick]}//(#b)(#s)([^\/]*)/$local_dir\/$dirname\/$match(#q.)}(DN)
> )
>

Thanks, I'll think about extending pick''.
-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
  2020-04-18 23:22               ` Sebastian Gniazdowski
@ 2020-04-19  0:02                 ` Bart Schaefer
  0 siblings, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2020-04-19  0:02 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Sat, Apr 18, 2020 at 4:24 PM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> On Sat, 18 Apr 2020 at 22:00, Bart Schaefer <schaefer@brasslantern.com> wrote:
>>
>> In this case, "useful" collides directly with "practical" given the
>> semantics of "/" imposed by the underlying file system.
>
> What do you mean?

I mean that given a directory tree a/b/c/d/e/f, you can't do
opendir("a/b/c") and then get back "d/e/f" from readdir(), whereas
every other pattern can be compared directly against a value returned
by readdir().

>  it puzzled me that such /-using patterns aren't allowed. Mikachu has a patch allowing them, maybe it's worth adding it to the upstream?:
>
> http://comm.it.cx/cgit/zsh-cvs/commit/?h=mika&id=512bd3f23ea8b4170d88582521d417cdb247413a

I don't think that actually does what you want.  This works:

% setopt jankypatterns
% ls -d (Completion/Base/Core|Completion/X/Type)
Completion/Base/Core    Completion/X/Type

But this doesn't:

% ls -d */(Base/Core|X/Type)
zsh: bad pattern: */(Base/Core|X/Type)
% ls -d (*/(Base/Core|X/Type))
zsh: no matches found: (*/(Base/Core|X/Type))

The latter failures are why Mikachu's patch is not presently suitable
for inclusion upstream.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: How to overcome the (a/b/c…)(N) pattern limitation?
       [not found]   ` <CAKc7PVCJfCwUUrm5KXzzehxuX1JF=Bvwkh=m7we_TiCrtw_fhQ__30396.4317821496$1587217473$gmane$org@mail.gmail.com>
@ 2020-04-19  6:44     ` Stephane Chazelas
  0 siblings, 0 replies; 12+ messages in thread
From: Stephane Chazelas @ 2020-04-19  6:44 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Roman Perepelitsa, Zsh Users

2020-04-18 15:41:37 +0200, Sebastian Gniazdowski:
> On Sat, 18 Apr 2020 at 14:56, Roman Perepelitsa <roman.perepelitsa@gmail.com>
> wrote:
> 
> > On Sat, Apr 18, 2020 at 2:51 PM Sebastian Gniazdowski
> > <sgniazdowski@gmail.com> wrote:
> > > I was trying to do: ls (/tmp/somedir/gh|./gh)(N)
> >
> > This should work:
> >
> >   ls {/tmp/somedir/gh,./gh}(N)
> >
> > Note that you'll get listing for the current directory if there are no
> > matches.
> >
> > Roman.
> >
> 
> I need the technique to be pattern-based – it is used in script in a
> $~pattern way.
[...]

Use an array:

pattern=({/tmp/somedir/gh,./gh}'(N)')
ls -ld -- $~pattern

-- 
Stephane

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-04-19  6:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18 12:49 How to overcome the (a/b/c…)(N) pattern limitation? Sebastian Gniazdowski
2020-04-18 12:55 ` Roman Perepelitsa
2020-04-18 13:41   ` Sebastian Gniazdowski
2020-04-18 13:45     ` Roman Perepelitsa
2020-04-18 14:07       ` Sebastian Gniazdowski
2020-04-18 14:07         ` Sebastian Gniazdowski
2020-04-18 14:31         ` Roman Perepelitsa
2020-04-18 14:41           ` Sebastian Gniazdowski
2020-04-18 20:00             ` Bart Schaefer
2020-04-18 23:22               ` Sebastian Gniazdowski
2020-04-19  0:02                 ` Bart Schaefer
     [not found]   ` <CAKc7PVCJfCwUUrm5KXzzehxuX1JF=Bvwkh=m7we_TiCrtw_fhQ__30396.4317821496$1587217473$gmane$org@mail.gmail.com>
2020-04-19  6:44     ` Stephane Chazelas

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).