* Re: Prompt expansion: $((%)foo} != $(print -P $foo)
@ 2000-03-20 12:04 Sven Wischnowsky
2000-03-20 17:11 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Sven Wischnowsky @ 2000-03-20 12:04 UTC (permalink / raw)
To: zsh-workers
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@informatik.hu-berlin.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Prompt expansion: $((%)foo} != $(print -P $foo)
2000-03-20 12:04 Prompt expansion: $((%)foo} != $(print -P $foo) Sven Wischnowsky
@ 2000-03-20 17:11 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2000-03-20 17:11 UTC (permalink / raw)
To: zsh-workers
On Mar 20, 1:04pm, Sven Wischnowsky wrote:
} Subject: 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 ...).
}
} Err... that's what (%%) is for.
D'oh! I should have remembered that ...
Index: Functions/Prompts/prompt_bart_setup
===================================================================
@@ -60,19 +60,10 @@
psvar[8]="$history[$#history]" # Use history text, not just number
psvar[9]='' # Padding before upper right prompt
- if [[ -o promptsubst ]]
- then
- # This is a bug workaround; ${(%)...} mishandles promptsubst
- repeat $[COLUMNS-${#${(%f)${${(e)PS1}//[%]\{[^%]#%\}/}}[1]}-1]
- do
- psvar[9]="$psvar[9] "
- done
- else
- repeat $[COLUMNS-${#${(%f)${PS1//[%]\{[^%]#%\}/}}[1]}-1]
- do
- psvar[9]="$psvar[9] "
- done
- fi
+ repeat $[COLUMNS-${#${(%%f)${PS1//[%]\{[^%]#%\}/}}[1]}-1]
+ do
+ psvar[9]="$psvar[9] "
+ done
}
prompt_bart_ps1 () {
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Prompt expansion: $((%)foo} != $(print -P $foo)
@ 2000-03-20 6:45 Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2000-03-20 6:45 UTC (permalink / raw)
To: zsh-workers
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.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2000-03-20 17:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-20 12:04 Prompt expansion: $((%)foo} != $(print -P $foo) Sven Wischnowsky
2000-03-20 17:11 ` Bart Schaefer
-- strict thread matches above, loose matches on Subject: below --
2000-03-20 6:45 Bart Schaefer
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).