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

Re: What's wrong with PROMPT_SUBST? (Was: VCS info (Re: Call for good plugins list))



On 2/12/20, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Tue, Feb 11, 2020 at 1:38 AM Lawrence Velázquez <vq@xxxxxxxxx> wrote:
>>
>> > On Oct 1, 2017, at 5:50 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
>> > wrote:
>> >
>> > The main thing is that I despise prompt_subst
>>
>> Why is that?
>
> Mostly it's a matter of taste.  It introduces yet another set of
> tokens that you have to escape to use literally in prompts, and I
> don't think the prompt is an appropriate place to be running command
> substitutions.  It means even more possible collisions on variable
> names with unintended side-effects.   Obviously these are things that
> can be avoided; I'd just rather not have to think about them.

One particular cargo culted piece of setup is the following combo,

setopt prompt_subst
preexec() {
  print -P "$escape_to_set_terminal_title $1 $end_terminal_title"
}

which will result in the following command having funny results,
echo '$(killall -9 zsh)'

(the above code is wrong even without prompt_subst but the
consequences are quite a bit worse with it). The easy fix with
prompt_subst enabled is to use \$1 instead which should be more or
less fine as long as you haven't literally typed in the
$end_terminal_title code.

-- 
Mikael Magnusson



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