3

I enter in zsh:

% PS1=">>> "

But for some reason, the prompt is still the same:

% echo $PS1
%B%F{red}%(?..%? )%f%b%B%F{blue}%n%f%b@%m %B%40<..<%~%<< %b%# 

Same thing with PROMPT.

It works well in bash and sh. How do I fix it?

6
  • Do you have perhaps some pre- or post-command hook that's overwriting your PS1?
    – DopeGhoti
    Feb 4 '19 at 19:40
  • I'm not sure what a hook is, I'm gonna check
    – Cansico
    Feb 4 '19 at 19:41
  • Oh-my-zsh isnt installed, neither a zsh theme configuration
    – Cansico
    Feb 4 '19 at 20:09
  • Run zsh -f, and then try. It will invoke new shell without looking into any initialization files. If that works then it means some part of your startup file overwrites the prompt (preexec and precmd functions are the most suspicious here).
    – jimmij
    Feb 4 '19 at 22:58
  • Also interesting is that the PS1 shown does not produce a single % as shown.
    – JdeBP
    Feb 4 '19 at 23:18
3

The precmd function (which is run before displaying a new prompt) was resetting the prompt. All I had to do was:

precmd_functions=""

(this removes all precmd "hook functions")

... and then I was able to change PS1. It's possible to change it permanently by adding this line to ~/.zshrc file.

1
  • maybe the cleanest way is to define env variable _Z_NO_PROMPT_COMMAND into your .zshrc file, Ref: ~/.oh-my-zsh/plugins/z/README
    – Vielinko
    Jun 12 '20 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.