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

Re: colorizing printfs



On Sat, May 11, 2024 at 2:54 AM Kannan Varadhan <kvaradhan3@xxxxxxxxx> wrote:
>
>
> My version:
>
> ~⦒zsh --version           ▮▮▮▮▮▮▯▯▯▯ 17:26:13
> zsh 5.9 (x86_64-pc-linux-gnu)
>
> I am trying out variations suggested here:  https://unix.stackexchange.com/questions/408867/how-to-colorize-some-of-the-output-of-a-shell-script
>
> and am confused.
>
>
> One of the last (I expect ideal) suggestions is:
>
> % text=xyz
>
> % printf '%s\n' "${(%):-%F{green}}$text${(%):-%f}"
>
>
> When I try it:
>
> ~⦒printf '%s\n' "${(%):-%F{blue}}test${(%):-%f}"                           ▮▮▮▮▮▯▯▯▯▯ 17:33:45
> }test
>
> I have a trailing `}' which I think I should not see.
>
> If I split this up,
>
> ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}}" "test" "${(%):-%f}"               ▮▮▮▮▮▯▯▯▯▯ 17:35:41
> }.test.
> ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}}${(%):-%B}" "test" "${(%):-%b}${(%):-%f}"
> }.test.
>
> same result.  The extra parenthesis, but the %B/%b print codes worked as expected.
>
> If my reading of the zsh man pages is correct, this one should be identical to the last one above,
>
> ~⦒printf '%s.%s.%s\n' "${(%):-%F{blue}%B}" "test" "${(%):-%b}${(%):-%f}"
> %B}.test.
>
> Instead I get the above `%B}' in the output.

You probably have a badly made / cargo culted precmd() function
active. At a guess, try changing $1 in that function to \$1 and it
might fix the problem.

-- 
Mikael Magnusson




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