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

Re: Prompt expansion: $((%)foo} != $(print -P $foo)



Bart Schaefer wrote:

> The order in which parameter expansion vs. prompt %x expansion takes place
> appears to be reversed for ${(%)...} and $(print -P ...).  This is visible
> in this situation:
> 
> zsh% setopt promptsubst
> zsh% PS1='%$[COLUMNS-20]>...%% >some text here %% '
> some text here %
> 
> The prompt and the output of "print -P" are truncated at COLUMNS-20, so in
> that case the $[...] was expanded before %N>...> was parsed.  However:
> 
> some text here % echo ${(%)PS1}
> [COLUMNS-1]some text here %
> 
> There, %$ was taken as a prompt token (and ignored) before parameters were
> expanded.  A workaround is to use ${(%)${(e)PS1}}, but of course that's not
> right when promptsubst is NOT set.

Err... that's what (%%) is for. From the docs:

item(tt(%))(
Expand all tt(%) escapes in the resulting words in the same way as in
prompts (see noderef(Prompt Expansion)). If this flag is given twice,
full prompt expansion is done on the resulting words, depending on the 
setting of the tt(PROMPT_PERCENT), tt(PROMPT_SUBST) and
tt(PROMPT_BANG) options.
)


Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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