Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: colorizing printfs
- X-seq: zsh-users 29933
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Cc: Mikael Magnusson <mikachu@xxxxxxxxx>, Kannan Varadhan <kvaradhan3@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: colorizing printfs
- Date: Tue, 14 May 2024 07:48:11 +0100
- Archived-at: <https://zsh.org/users/29933>
- In-reply-to: <CAN=4vMpFktpOPyN2B1YAEaP1mETMJ7aR7oE48J3x18X1DvY0bg@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Mikael Magnusson <mikachu@xxxxxxxxx>, Kannan Varadhan <kvaradhan3@xxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <8d1d947e-75af-4a9a-b726-dabe9858b2b0@gmail.com> <CAHYJk3RxmfABttta9798mQfav+uFa3wv9tFpMiqAj6A0UrwNsA@mail.gmail.com> <CAN=4vMpFktpOPyN2B1YAEaP1mETMJ7aR7oE48J3x18X1DvY0bg@mail.gmail.com>
2024-05-11 16:37:03 +0200, Roman Perepelitsa:
> On Sat, May 11, 2024 at 4:27 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> >
> > On Sat, May 11, 2024 at 2:54 AM Kannan Varadhan <kvaradhan3@xxxxxxxxx> wrote:
> > >
> > >
> > > ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}%B}" "test" "${(%):-%b}${(%):-%f}"
> > > %B}.test.
> >
> > You probably have a badly made / cargo culted precmd() function
> > active.
>
> That output is actually expected. The right curly must be escaped.
>
> printf '%s.%s.%s\n' "${(%):-%F{blue\}%B}" "test" "${(%):-%b}${(%):-%f}"
[...]
Thanks, I've fixed
https://unix.stackexchange.com/questions/408867/how-to-colorize-some-of-the-output-of-a-shell-script/408871#408871
(which was at the start of the discussion) accordingly.
> Or, when printing $var:
>
> print -rP '%F{blue}%B'${var//\%/%%}'%b%f'
[...]
It should be noted (as I now have in my answer above) that that
assumes the promptbang and promptsubst options are disabled and
promptpercent is enabled, with possible dramatic effect if not
(like when $var contains $(reboot) and promptsubst is enabled).
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author