* Probs with nested braces in PROMPT
@ 2000-07-06 9:34 Bernd Eggink
2000-07-06 9:59 ` Andrej Borsenkow
0 siblings, 1 reply; 6+ messages in thread
From: Bernd Eggink @ 2000-07-06 9:34 UTC (permalink / raw)
To: Zsh Users
Are nested braces supposed to work in PROMPT (zsh 3.1.9-dev-2)?
I tried this:
PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+ %{^[[31m[%}}$PROJECT${PROJECT:+]%{^[[30m%}}%#%{^[[0m%}'
which looks good if PROJECT is set, for example with PROJECT=ecc:
eggink3:1 11:25 ~/necht [ecc]%
(actually nicely coloured). However, when PROJECT is not set, it results
in something ugly:
eggink3:1 11:26 ~/necht}}%
Bug or feature?
Regards,
Bernd
--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Probs with nested braces in PROMPT
2000-07-06 9:34 Probs with nested braces in PROMPT Bernd Eggink
@ 2000-07-06 9:59 ` Andrej Borsenkow
2000-07-06 10:12 ` Peter Stephenson
2000-07-06 11:03 ` Bernd Eggink
0 siblings, 2 replies; 6+ messages in thread
From: Andrej Borsenkow @ 2000-07-06 9:59 UTC (permalink / raw)
To: Bernd Eggink, Zsh Users
>
> PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+
> %{^[[31m[%}}$PROJECT${PROJECT:+]%{^[[30m%}}%#%{^[[0m%}'
>
You do have promptsubst set, don't you?
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.
-andrej
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Probs with nested braces in PROMPT
2000-07-06 9:59 ` Andrej Borsenkow
@ 2000-07-06 10:12 ` Peter Stephenson
2000-07-06 10:19 ` Andrej Borsenkow
2000-07-06 11:03 ` Bernd Eggink
1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2000-07-06 10:12 UTC (permalink / raw)
To: Zsh users list
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@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: Probs with nested braces in PROMPT
2000-07-06 10:12 ` Peter Stephenson
@ 2000-07-06 10:19 ` Andrej Borsenkow
2000-07-06 11:09 ` Peter Stephenson
0 siblings, 1 reply; 6+ messages in thread
From: Andrej Borsenkow @ 2000-07-06 10:19 UTC (permalink / raw)
To: Peter Stephenson, Zsh users list
>
> 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.
Yes, of course. But why it did it only when parameter was undefined? I
mean, parsing is done by lexer - and it has to find the closing brace in
any case and lexer does not know (is it true?) about parameter values.
That is incosistent IMHO and smells more like a bug.
-andrej
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Probs with nested braces in PROMPT
2000-07-06 9:59 ` Andrej Borsenkow
2000-07-06 10:12 ` Peter Stephenson
@ 2000-07-06 11:03 ` Bernd Eggink
1 sibling, 0 replies; 6+ messages in thread
From: Bernd Eggink @ 2000-07-06 11:03 UTC (permalink / raw)
To: Zsh Users
On Thu, Jul 06, 2000 at 01:59:53PM +0400, Andrej Borsenkow wrote:
> >
> > PROMPT='%{^[[5;46m%}%m:%l %T %~${PROJECT:+
> > %{^[[31m[%}}$PROJECT${PROJECT:+]%{^[[30m%}}%#%{^[[0m%}'
> >
>
> You do have promptsubst set, don't you?
>
> 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.
Thanks, this works. My first attempt was to quote both of the braces %\{
... %\}, but that resulted in something like this:
eggink3:2 13:01 ~/necht {[ecc]{%
Regards,
Bernd
--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Probs with nested braces in PROMPT
2000-07-06 10:19 ` Andrej Borsenkow
@ 2000-07-06 11:09 ` Peter Stephenson
0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2000-07-06 11:09 UTC (permalink / raw)
To: Zsh users list
> Yes, of course. But why it did it only when parameter was undefined? I
> mean, parsing is done by lexer - and it has to find the closing brace in
> any case and lexer does not know (is it true?) about parameter values.
>
> That is incosistent IMHO and smells more like a bug.
No, in that case it got the `%{...%' from inside the braces, then found the
(wrong) closing brace, then found the neglected `}' from the parameter
expansion, therefore getting the complete expression %{...%}. In this case
it didn't matter which brace was which.
--
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2000-07-06 11:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-06 9:34 Probs with nested braces in PROMPT Bernd Eggink
2000-07-06 9:59 ` Andrej Borsenkow
2000-07-06 10:12 ` Peter Stephenson
2000-07-06 10:19 ` Andrej Borsenkow
2000-07-06 11:09 ` Peter Stephenson
2000-07-06 11:03 ` Bernd Eggink
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).