Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [tip] mouse support
- X-seq: zsh-users 8208
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Zsh users list <zsh-users@xxxxxxxxxx>
- Subject: Re: [tip] mouse support
- Date: Fri, 12 Nov 2004 09:22:26 +0000
- In-reply-to: <Pine.LNX.4.61.0411111647290.13126@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Zsh users list <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20041111122011.GB4451@sc> <4483.1100184032@xxxxxxx> <20041111162209.GC4451@sc> <Pine.LNX.4.61.0411110943030.30994@xxxxxxxxxxxxxxxxxx> <20041111182225.GA4345@sc> <Pine.LNX.4.61.0411111647290.13126@xxxxxxxxxxxxxxxxxx>
On Thu, Nov 11, 2004 at 05:02:47PM -0800, Bart Schaefer wrote:
> On Thu, 11 Nov 2004, Stephane Chazelas wrote:
>
> > zero='%([BSUbsu]|{*%})'
> >
> > It replaces '%%some %{%{some%}%}' with '%ome %}' instead of
> > '%%some '
>
> Hmm. To fix that, you need extended globbing:
>
> setopt extendedglob
> zero='(#b)([^%]|(#s))%([BSUbsu]|{*%})'
> print ${(%%)PS1//$~zero/$match[1]}
[...]
That moves the problem (the first one)
ow, there's a problem with '%%%S'
A better fix:
zero='(#b)(%([BSUbsu]|{*%})|(%[^BSUbsu{}]))'
print ${(S%%)PS1//$~zero/$match[3]}
But, it still doesn't fix the problem of nested %{ (maybe not
too big an issue, as I can't think of any case where nesting
%{'s can be useful).
> On Thu, 11 Nov 2004, Stephane Chazelas wrote:
>
> > Well the (%%) expansion flag has another problem:
> >
> > var='%Sfoo%s'
> > PS1='$var'
> >
> > In that case, you need to expand first the variables in PS1 or
> > you'll miss the %S %s visual sequences.
>
> That's easy enough:
>
> if [[ -o promptsubst ]]
> then print ${(%%)${(e)PS1}//$~zero/$match[1]}
> else print ${(%%)PS1//$~zero/$match[1]}
> fi
Yes, that was what I did. Except that I used (%) instead of
(%%). But with (%%) PS1 may be expanded again (PS1='$(echo "\$foo")')
So a refined solution could be:
local cur_prompt
if [[ -n $PREBUFFER ]]; then
cur_prompt=$PS2
# decide wether we're at the PS2 or PS1 prompt
else
cur_prompt=$PS1
fi
[[ -o promptsubst ]] && cur_prompt=${${(e)cur_prompt}//(#b)([\\\$\`])/\\$match}
# restore the exit status in case $PS<n> relies on it
set-status $last_status
cur_prompt=${(S%%)cur_prompt//(#b)(%([BSUbsu]|{*%})|(%[^BSUbsu{}]))/$match[3]}
what do you think?
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author