Skip to content

Don't add current command to history (ignore flag) #22

Closed Answered by marlonrichert
martin-braun asked this question in Q&A
Discussion options

You must be logged in to vote

That's already possible in Zsh natively. You have three options for this, all of which can be combined:

  • Add setopt HIST_IGNORE_SPACE to your .zshrc file. Then, if you insert at least one space at the very beginning of a command line, it will not be saved to history, although it is still saved to local history in memory.
  • Add HISTORY_IGNORE=<glob pattern to your .zshrc file. Then, any command line that matches that pattern will not be saved to history.
  • Add a history hook function to your .zshrc file:
    autoload -Uz
    <function>() {
      <logic>
    }
    add-zsh-hook zshaddhistory <function>
    Then, whenever you submit a command line, before it is executed, it will be passed to this function. If the functi…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by marlonrichert
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
documentation Improvements or additions to documentation
2 participants
Converted from issue

This discussion was converted from issue #21 on May 24, 2023 12:24.