Zsh needs to know how wide the prompt is in order to get the cursor position right. If it assumes an incorrect value for the width of the prompt, it will write text at the wrong place when redrawing the command line. That's what's happening after zsh moves to the next line to display possible completions: it redraws the command to be completed at the position where it thinks it should appear.
Your prompt contains escape sequences that have a width of zero: their effect is to change the appearance of the following text. Zsh doesn't know that: it assumes that every character has a width of 1 unless told otherwise. To tell zsh that a part of the prompt has a width of zero, surround it by %{…%}
.
PROMPT=%{$(printf "\e[38;5;6m")%}%m%{$(printf "\e[m")%}%d-%h:" "
You can simplify this: there's no need to invoke printf
, you can use the $'…'
syntax to include backslash escapes.
PROMPT=$'%{\e[38;5;6m%}%m%{\e[m%}%d-%h: '
Don't export PROMPT
: it's an internal shell variable, not an environment variable that other applications are meant to see.
Zsh has prompt escape sequences to change the text appearance in simple ways. I'm not sure what you intend with 38;5;6
. Bold blue would be 34;1
, or with zsh prompt escapes,
PROMPT='%F{blue}%B%m%b%f%d-%h: '