How to configure zsh to clear history on exit?

This used to be the default behavior on iTerm2 before I upgraded to macOS Calalina.

0

2 Answers

This is not configured in iTerm2, but is set by macOS in Zsh itself. Since macOS Catalina, the file /etc/zshrc contains the following:

HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history HISTSIZE=2000 SAVEHIST=1000 

This causes the last 1K lines of history to be saved on exit.

To override this, add the following to your ~/.zshrc file:

unset HISTFILE SAVEHIST 

Documentation:

1

Step 1.

%> echo "\n# Clear ZSH history after each exit.\ntrap 'unset HISTFILE; rm ~/.zsh_history;HISTSIZE=0;'" >> .zshrc

Now reload your ZSH terminal and you will never have history saved again unless you remove the above line from your .zshrc :).

You're done!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like