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

Re: colorizing printfs



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