That's a specific feature of zsh
(and now fish
as well) to let you clearly see unterminated lines in a command's output.
In traditional shells, if a command outputs some data after the last newline character, or, in other words, if it leaves the terminal cursor not at the start of the line, the next prompt by the shell ends up appended to that last unterminated line as in:
bash-4.4$ printf XXX
XXXbash-4.4$
That mangles the prompt, and it's easy to miss that XXX
there especially if you've got a fancier prompt than that. It also affects cursor positioning which causes display glitches when you move the cursor around.
zsh
works around that, by showing that the output has an unterminated line with a %
character in bold and reverse video, and issues the next prompt at the beginning of the next line:
zsh-5.1.1$ printf XXX
XXX%
zsh-5.1.1$
It does that by outputting that reverse video %
at the end of every command (before each prompt), but followed by 79 spaces (assuming a 80 character wide terminal), a CR character (the one that causes the cursor to go back to the first column) and the sequence to erase to the end of the line (and then the prompt).
That way, if there was an unterminated line, since the cursor is not in first position, those 80 characters will make the cursor move to the next line (and that %
will stay). If not, then that %
and those 79 spaces will be on a one line which will be deleted afterwards.
Now, that only works if the terminal does wrap lines (for instance, that won't work properly after tput rmam
). If you have a slow terminal (like on 9600 baud serial line), you may actually see those %
being displayed and then removed after each command, so zsh
lets you disable that feature:
set +o prompt_cr +o prompt_sp
That way, zsh
behaves more like traditional shells.
You can also change that mark with the $PROMPT_EOL_MARK
variable.
print -n "this is a test"
thenprint "this is a test"
– SergioAraujo Aug 06 '17 at 11:49PROMPT_EOL_MARK=''
into my .zshrc to hide the difference between trailing newline or not on command output. – geekQ Jun 29 '18 at 12:59PROMPT_EOL_MARK=
to just have no extra chars at all. – Max Cascone Feb 06 '23 at 17:53