zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: coloring a substitution
Date: Tue, 8 Nov 2022 22:10:07 +0100	[thread overview]
Message-ID: <CAN=4vMqMsigw20xAdLGcTNmTVKWe4chtFRWLdcXdXS4zQR_Q2w@mail.gmail.com> (raw)
In-Reply-To: <5454df12-02c6-75b5-e552-c486e231183c@eastlink.ca>

On Tue, Nov 8, 2022 at 9:57 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> I'm seeing if I can make my function 100% zsh native.  The 'sed' works.
> '$color' is just incrementing integers in a for loop starting at 31 (red):
>
>   recent[$aa]=$( print $recent[$aa] | sed -r
> "s/$filter/\x1b\[$color;1m$filter\x1b\[0m/Ig" )

I'm assuming that:

- `print` is equivalent to `print -r --` here
- $filter doesn't have any metacharacters
- it's intentional that $filter is matched case-insensitively and
whatever matches is replaced literally by $filter

The last assumption looks the most weird to me and there is a chance
that this isn't what you intended the code to do.

> ... so I'm trying to get zsh string replacement to do the same job:
>
> recent[$aa]=${recent[$aa]/\x1b\[$color;1m$filter\x1b\[0m/}

Try this:

  recent[$aa]=${recent[$aa]//(#i)$filter/$'\e['$color';1m'$filter$'\e[0m'}

Roman.


  reply	other threads:[~2022-11-08 21:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 20:56 Ray Andrews
2022-11-08 21:10 ` Roman Perepelitsa [this message]
2022-11-08 23:49   ` Ray Andrews
2022-11-09  0:11     ` Bart Schaefer
2022-11-09  0:32       ` Ray Andrews
2022-11-09  8:19     ` Roman Perepelitsa
2022-11-11 22:24       ` Ray Andrews
2022-11-11 22:39         ` Roman Perepelitsa
2022-11-12  3:36           ` Ray Andrews

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='CAN=4vMqMsigw20xAdLGcTNmTVKWe4chtFRWLdcXdXS4zQR_Q2w@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@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).