When displaying the history number of the next command in zsh's prompt (I'm on version 5.0.2), it is unexpectedly incremented after ignored histignorespace and histnostore commands (and then only "corrects" itself after the next command) but works as I'd expect after ignored histignoreddups commands.

Is there a good reason for the difference in behavior? Can I make the prompt consistently show the history event for the next (not ignored) command, even if it is following an ignored "spaced" or history command?

histignorespace suprises me:

% PROMPT='%! >' zsh --no-rcs --histignorespace
1 > true ignore me
2 >true two
2 >history
    1  true two

As does histnostore (also I thought it odd the immediate invocation includes itself):

% PROMPT='%! >' zsh --no-rcs --histnostore
1 >history
    1  history
2 >true two
2 >history
    1  true two

But histignoredups works as I'd expect:

% PROMPT='%! >' zsh --no-rcs --histignoredups
1 >true repeated
2 >true repeated
2 >true two
3 >history
    1  true repeated
    2  true two

Is there a good reason for the difference in behavior?

Yes. The Z Shell is behaving as documented in its manual:

Note that the command lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the line.

Read the zshoptions manual for full information.

  • I did read that, and you're right to point it out as the likely underlying reason why ignorespace and nostore share the behavior, but I'm not sure if that counts as a "good reason". Couldn't I also argue zsh is not behaving as documented where it describes the prompt expansion as "the number that is to be assigned to the next command"? – plnx Feb 12 '15 at 21:35

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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