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

Re: Why are prompt expansions of %v sequences quoted in bindkey style?



On 1/24/24, Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
>> On 23. Jan 2024, at 22.21, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> On 1/23/24, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>>> On Tue, Jan 23, 2024 at 10:44 AM Marlon Richert
>>>> <marlon.richert@xxxxxxxxx> wrote:
>>>>
>>>> However, the quoting seems to make it impossible to use $psvar for
>>>> anything involving control characters.
>>>
>>> That's correct.  Anything involving control characters would also
>>> require %{...%} or %G to specify the occupied screen width.
>>>
>>>> Is there no way to work around this?
>>>
>>> As Roman mentioned, the usual way is to use precmd to update prompt
>>> values.
>>
>> fwiw, you can do things like %F{%5v}hello or %(3V.%B.) to make things
>> dynamic without using promptsubst or updating PS1 in precmd, but you
>> do have to have all the actual formatting in PS1 then.
>>
> Thanks, I think that might work for me.
>
> I am indeed trying to use $psvar to dynamically update my prompt’s visual
> formatting, without the use of prompsubst or changing $PS1.

Thinking about this made me realize that namerefs can be quite useful here, eg
typeset -n .prompt.logicaldescription='psvar[3]'
then you don't have to remember what number you decided to use for
what (I always forget what I picked). And it makes code using them
slightly more self descriptive.

-- 
Mikael Magnusson




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