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

Re: coloring substitution seems to eat next line.



On Thu, Nov 10, 2022 at 10:42 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
>
> On 2022-11-10 12:22, Bart Schaefer wrote:
> >
> > Most of the time you want the parens when assigning all the elements
> > of an array at once.  You should not use the parens for anything
> > that's meant to be a single string (or number).
> Slowly I figure out what's really going on and don't have to rely on
> rote copying of syntax.
> > local MATCH MBEGIN MEND
> > which should never appear except inside a function, and should only
> > appear at the beginning of the function and not inside a loop.
> Heavy duty diagnostic stuff it seems.
> > $~foo (or ${~foo} means that the value of $foo should be interpreted
> > as a glob pattern rather than as a literal string.
>
> Ah!  When you type it in there verbatim it seems to always be the
> pattern, but as a variable who's to say that the intention is?  So some
> way of making it explicit avoids semantic confusion.  That's robust, I
> like it.  One more little thing:
>
>
> string="${cc[$aa]/*(#i)$filter*/}"
> if [[ "$string" ]]; then
> cc[aa]=''
> else
> cc[$aa]=${cc[$aa]/(#b)($~zsh_case${filter})/$'\e['$color;1m${match[1]}$'\e[0m'}

If you look back, you can find in my answers a way to:

1. Remove all elements of an array that don't match a pattern. It has this form:

  array=(${(M)array:#pattern})

2. Perform a replacement in all elements of an array. Like this:

  array=(${array//pattern/substitute})

Perhaps now you have enough familiarity with the syntax to see how it works.

You can save a tremendous amount of time by reading the official guide
and the reference. Set aside an evening or two and read them from
start to end. Exploring a language as a science project is a great way
to get started but at some point you'll become more efficient by
reading the blueprint. After that the language becomes an artifact
rather than a blackbox.

Roman.




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