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

Re: Good documentation about literal escape sequences in prompt?



Juhapekka Tolvanen (juhtolv@xxxxxxxxx) wrote:
> 
> %{...%}
>         Include a string as a literal escape sequence. The
>         string within the braces should not change the cursor
>         position. Brace pairs can nest.
> 
> Hey, come on! Do you really think that is enough? Why don't you provide some
> good examples? I know you can do it better!
> 
> For example this does not work:
> 
> PS1="%{\e[1;31m%}$PS1%{\e[1m%}"

That's because \e doesn't mean anything special within double-quotes;
it only gets interpreted as ASCII 27 when used inside $'' quotes, or
from the `print', `echo', or `bindkey' built-ins.  So what you want
is:

PS1=$'%{\e[1;31m%}'"$PS1"$'%{\e[1m%}'

I also made this mistake when first messing around with prompts, so it
looks like the relevant docs could indeed do with a bit of
improvement.  (Would do this myself, but still waiting for someone to
give me the go-ahead on sourceforge, or at least make up-to-date
snapshots available so that I can submit reliable patches.  Anyone
planning to release dev-20 before pws comes back?)

Adam



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