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

Re: When RPROMPT != RPS1



Peter Stephenson writes:

> On Wed, 21 Jun 2017 10:16:45 -0700
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>> I don't have a good suggestion for how to satisfy both constraints.
>> Anyone?  The parameter initialization code has been broken up into
>> a few more sections already, maybe there's a way to rearrange these
>> as well.
>
> We can at least make it less likely people are going to trip over the
> complications if they're simply using the prompt system.
>
> pws

If I understand the problem correctly, the issue is not just limited to
the right prompts. The different themes set different prompt variables,
so when you change between themes you get a prompt setup that depends on
the history of themes you used.

For example, if I do

autoload -Uz promptinit; promptinit
prompt clint
echo $PS3

I get

?#

But if I do

autoload -Uz promptinit; promptinit
prompt adam1
prompt clint
echo $PS3

I get

%K{blue}%n@%m%k %B%F{green}%147<...<%~
%}%F{white} ?# %b%f%k

Interestingly, there is no problem with the prompt functions like
precmd, preexec etc. as the configuration of the previously active theme
gets deleted in set_prompt right before the new theme is activated:

local hook
for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do
  add-zsh-hook -D "${hook}" "prompt_*_${hook}"
done

I think one solution for getting a consistent setup might be to add some
code at the same place that restores the prompt variables to their
default values.
Maybe something along the lines of what I included below (which seems to
solve the problem on my system). However, this breaks the bart theme as
it has a mode of operation where one can set the right prompt before
activating the theme.

Best,  
Daniel

diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index 587248997..0bc9b1ab4 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -160,6 +160,11 @@ Use prompt -h <theme> for help on specific themes.'
        for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do
          add-zsh-hook -D "${hook}" "prompt_*_${hook}"
        done
+       PS1='%m%# '
+       PS2='%_> '
+       PS3='?# '
+       PS4='+%N:%i> '
+       unset RPROMPT RPS1 RPROMPT2 RPS2
        typeset -ga zle_highlight=( ${zle_highlight:#default:*} )
        (( ${#zle_highlight} )) || unset zle_highlight



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