I do have the following config in my .zshrc:
BEL=$(tput bel)
PROMPT+='%(?::$BEL)'
That works/worked in some environment (always Cygwin on Windows), but currently does not anymore.
(Same behaviour: not working, in Bash on Ubuntu on Windows.)
What is wrong?
In zsh
, unlike bash
, parameter expansions embedded in a prompt are only expanded when the prompt is displayed if the PROMPT_SUBST
option is set.
%(...)
is a zsh
-specific escape sequence, and PROMPT
itself is a zsh
-specific name, so this will not work in bash
, which would require something like
PS1+='$(if test $? -ne 0; then tput bel; fi)'
(which, incidentally, would work in zsh
as well, assuming PROMPT_SUBST
were enabled. A command that would conditionally enable it if the current shell is, in fact, zsh
, might be
if [ -z "$ZSH_VERSION" ]; then
setopt PROMPT_SUBST
fi