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

Re: Probs with nested braces in PROMPT



Andrej wrote:
> >
> > PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+
> > %{^[[31m[%}}$PROJECT${PROJECT:+]%{^[[30m%}}%#%{^[[0m%}'
> >
>
> What about
> 
> PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+
> %{^[[31m[%\}}$PROJECT${PROJECT:+]%{^[[30m%\}}%#%{^[[0m%}'
> 
> (note, that `}' in %} are quoted). This seems to work. I suspect, why it
> happens, but I do not know code good enugh.

The problem was that ordinary ${...} doesn't know about %-substitution in
prompts, nor should it (that would be a horrendous complication involving
different levels of substitution).  So it took the brace in `%}' as the
brace closing the substitution.  Andrej's solution is the easiest way
round.  Because of the way parameters are parsed, you could also do

esc1=$'%{\e[31m%}'
esc2=$'%{\e[30m%}'
PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+
${esc1}[}$PROJECT${PROJECT:+]$esc2}%#%{^[[0m%}'

(replace line break by a space again) which you might consider neater.
You could even put the other escape sequences in that form:  the $'\e'
saves you having literal ASCII escapes in your text.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



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