zsh-workers
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: "Lawrence Velázquez" <vq@larryv.me>
Cc: scowles@ckhb.org, zsh-workers@zsh.org
Subject: Re: using dynamic patterns on the left hand side of case statement clauses
Date: Thu, 19 Mar 2020 00:38:02 -0400	[thread overview]
Message-ID: <20200319043802.GA27914@fullerene> (raw)
In-Reply-To: <AF902420-F42E-4C0A-B33F-65993E9DD89F@larryv.me>

On 2020-03-18 at 21:29 -0400, Lawrence Velázquez wrote:
> Search the zshexpn(1) man page for "${~spec}" for a more thorough
> explanation, but the '~' basically turns GLOB_SUBST on for just
> that parameter expansion.

Good stuff, but I'll offer up one refinement: you can turn on GLOB_SUBST
just for the joining pattern, without turning it on for the entire
pattern.

    % a=('a*' beta gamma delta)
    % c=('alpha', 'a*' 'apple')
    % for d in $c; do case $d in
        ${(j:|:)~a} ) echo "match in a for ${(q-)d}" ;;
        *) echo "no match for ${(q-)d}" ;;
      esac; done
    match in a for alpha,
    match in a for 'a*'
    match in a for apple
    % for d in $c; do case $d in
        ${(~j:|:)a} ) echo "match in a for ${(q-)d}" ;;
        *) echo "no match for ${(q-)d}" ;;
      esac; done
    no match for alpha,
    match in a for 'a*'
    no match for apple

You can thank Peter Stephenson for adding the support for that, when I
was asking about implementing set manipulation for arbitrary content
using zsh auto-unique arrays, some years ago now.

-Phil

  reply	other threads:[~2020-03-19  4:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-18 23:54 scowles
2020-03-19  1:29 ` Lawrence Velázquez
2020-03-19  4:38   ` Phil Pennock [this message]
2020-03-19  5:25     ` Lawrence Velázquez
2020-03-19 17:47       ` scowles

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=20200319043802.GA27914@fullerene \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=scowles@ckhb.org \
    --cc=vq@larryv.me \
    --cc=zsh-workers@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).