The interactions are so complex that I don't know exactly what I'm looking for, but maybe you can still help.

Sometimes, generally after an error (return code > 0), when recalling some last command, I do have a spurious character inserted in front of the command-line.

> dls WEB-INF 
  ^ (d is inserted, but can be another letter)

I'm wondering if it's because of my prompt definition

autoload -Uz vcs_info
precmd_vcs_info() {
precmd_functions+=( precmd_vcs_info )
setopt PROMPT_SUBST                     # Allow parameter expansion in prompt.
zstyle ':vcs_info:git:*' formats '%F{cyan}(%b)%f'
zstyle ':vcs_info:*' enable git

%B%(?.%F{green}.%F{red}$(tput bel)"$'\u2718'" %? )%f%b%F{green}%n@%m%F{black}%B:%b%F{yellow}%~ %f\$vcs_info_msg_0_
%F{magenta}%(!.#.$)%f "
                                        # ? - Exit code of the previous command.
                                        # n - User name.
                                        # m - Machine name.
                                        # . - Abbreviated pwd.
                                        # ! - su?

… or something else?

For the sake of clarity, my normal prompt is:

(blank line)
user@host:/path/to/current/dir (Git info)

and, if an error occurred with the last command, it is then:

(blank line)
x 127 user@host:/path/to/current/dir (Git info)

(where 127 is the return code of the last command.)

I can't reproduce the problem easily, I'm still wondering about the triggering (set of) condition(s).

However, I've also notice that my Zsh history did contain \n characters after some commands

 6848  2020-04-09 14:09  while true; do sleep 1; done
 6849  2020-04-09 14:10  dirax-flow-reverse ab-helpdesk-sla-create-priority-level-tab.js\n\n
 6850  2020-04-09 14:10  ls WEB-INF
 6851  2020-04-09 14:10  ls WEB-INF2

... and recalling those (with the Up key) could provoke the described error, but not always.

The fact that I do have some newline character at the end of some commands, is it that, the problem to be solved? Or it's another one, unrelated? (maybe coming from copy/pasting commands from a text file, where I do have some instructions to follow.)

If you see clearer than I do, any help is warmly appreciated!


1 Answer 1


You have a few options to try checking here.

  1. Are keybindings involved? Try recovering the last command with !!<Enter> (you mention using Up arrow). See https://unix.stackexchange.com/questions/147563/how-do-i-repeat-the-last-command-without-using-the-arrow-keys, https://stackoverflow.com/questions/25295186/access-to-last-command-in-zsh-not-previous-command-line

  2. Is the prompt involved? Remove all settings for your prompt.

Besides, did the system work fine at any point? Did you change anything?

Please post feedback to help others help you.

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.