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

Re: Prompt width miscomputed with conditional substring



07.04.2015, 00:09, "Bernie Innocenti" <bernie@xxxxxxxxxxx>:
> My zsh prompt is:
>
> local ret_status="%(?:%{$fg_bold[green]%}%%:%{$fg_bold[red]%}%%%s)"
> PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m:%{$fg[yellow]%}%~
> %(1j,$fg[cyan][%j],)${ret_status}%{$reset_color%} "
>
> When I have background jobs, the prompt becomes 3 characters longer and
> command-line editing seems to wrap at the wrong column.
>
> This is also reproducible with zsh built from git (zsh-5.0.7-374-gd4f50f2).
>
> --
>  _ // Bernie Innocenti
>  \X/  http://codewiz.org

This is expected because you have not wrapped `$fg[cyan]` properly after %(1j. This is not a bug.

I would highly suggest to drop and forget colors function. If you need colors just use %F{green}…%f to highlight with green. Specifically read man zshmisc, section “SIMPLE PROMPT ESCAPES”, subsection “Visual effects”.

If you think that $fg[cyan] is useful outside of prompt note that you may use ${(%):-%F{green}} (though `$fg[cyan]` is better when you don’t have to write it as `%{$fg[cyan]%}` and can’t just write `%F{green}` because you are not in prompt).



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