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

Re: colorizing printfs



On Sun, May 12, 2024 at 2:19 AM Kannan Varadhan <kvaradhan3@xxxxxxxxx> wrote:
>
> On 5/11/24 07:37, Roman Perepelitsa wrote:
> >
> >
> > That output is actually expected. The right curly must be escaped.
> >
> >     printf '%s.%s.%s\n' "${(%):-%F{blue\}%B}" "test" "${(%):-%b}${(%):-%f}"
>
> Yes, this works,
>
> Is this something that I missed in the documentation?

I don't know if it's documented but it makes sense if you consider
these examples:

    % print "${foo:-bar}baz"
    barbaz
    % print "${foo:-bar}baz}"
    barbaz}
    % print "${foo:-{bar}baz}"
    {barbaz}

"{" isn't special on its own unless it is preceded by "$". Thus, the
first "}" encountered after "${" marks the end of the expansion.

Roman.




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