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 7:25 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> On 2022-11-10 00:02, Roman Perepelitsa wrote:
>
> > Differences in the second version compared to the first:
> Sorry about the sloppy code Roman,  the differences there don't matter
> but you have no way of knowing that.
> > - aa instead of $aa
> Does that matter?  I thought it was one of those situations where the
> dollar sign is optional.

It matters if cc is an associative array. Given that you've
(accidentally) used slice assignment with cc, it cannot be an
associative array.

> > - slice assignment instead of scalar (almost certainly unintended)
> I've never heard of slice assignment :(

These two aren't the same:

  cc[42]="foo bar"
  cc[42]=(foo bar)

The second is a slice assignment.

> > This means you can replace
> > the whole loop with this:
> >
> >    local MATCH MBEGIN MEND
> >    cc=(${cc//(#m)$~zsh_case$filter/$'\e[31;1m'$MATCH$'\e[0m'})
>
> Unfortunately not.  That works as you intend, but I need to filter not
> just colorize. Any line without all matches must be deleted

You can filter beforehand like this:

  cc=(${(M)cc:#*$filter*})

This assumes that $filter doesn't have metacharacters. If it does and
you want to treat them as such, use $~filter.

Roman.




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