1

On macOS, there is a sessions directory that combines commands from multiple zsh sessions into a single history file.

Is it necessary to use shell options in the .zshrc file, to manipulate how zsh handles history, so that commands are appended to .zsh_history, or are these options redundant and ignored?

I see many people recommend, when transitioning from bash to zsh, to add the following options to make history include commands from other sessions and add other functionality (that appears to be built in):

APPEND_HISTORY
HISTFILE=~/.zsh_history
HISTSIZE=100000000
SAVEHIST=100000000
setopt INC_APPEND_HISTORY
[...]

However, it seems those are built in and needn't be specified.

Bonus question: Can one list multiple shell options after a single setopt, instead of having each option in a separate setopt statement?

3

On macOS, /etc/zshrc contains (among other things), the following lines:

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

This is the reason you don't need to set those on macOS; it's already done for you. However, you are of course free to modify those in your .zshrc file. Note, though, that it's recommended to make $HISTSIZE at least 20% larger than $SAVEHIST. Read https://zsh.sourceforge.io/Doc/Release/Options.html#History for more info.

If (and only if) you are using Apple's Terminal.app, then /etc/zshrc in turn calls /etc/zshrc_Apple_Terminal. In there, we find (among other things):

# Resume Support: Save/Restore Shell State

followed by a bunch of code ported from macOS's /etc/bashrc_Apple_Terminal. On , this code is largely unnecessary, as zsh can do the same with just setopt sharehistory.

To disable Apple's shell state code, add to your .zshenv file:

SHELL_SESSIONS_DISABLE=1

Then add to your .zshrc file:

setopt sharehistory

Also, make sure you unset all options incompatible with SHARE_HISTORY. Again, read https://zsh.sourceforge.io/Doc/Release/Options.html#History for more info.

Finally, feel free to delete the .zsh_sessions dir created by Apple's code, as it will no longer be necessary.


Bonus question: can we list options after setopt instead of having each one on a new line?

Yes, you can pass as many options as you like to setopt. Just try it on the command line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .