I am running Mojave have changed default shell from bash to zsh. I notice history is not saved between sessions.

Following recommendations in What are the practical differences between Bash and Zsh? I ran :

autoload -U zsh-newuser-install

This created the files ~/.zshrc and ~/.histfile which I did not have before but the history seems not to be updated.

A1398% cat .zshrc 
# Lines configured by zsh-newuser-install
setopt beep
bindkey -e
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/Users/hali/.zshrc'

autoload -Uz compinit
# End of lines added by compinstall
A1398% cat .histfile 

On opening a new session (either Terminal or iTerm2) there is nothing previous and up arrow for previous commands does nothing.

Do I understand correctly and history should be in ~/.histfile? Are there any other required steps?

  • Can't replicate it in my VM (Catalina though) after dumping my .zprofile and relaunching Terminal...it (your .zshrc) just works – klanomath Nov 29 '19 at 20:04
  • 1
    Do you type exit to terminate a shell session? – fd0 Nov 29 '19 at 20:07
  • Why not continue running bash? The only one who thinks you need to change your shell is you. – Marc Wilson Nov 29 '19 at 23:39
  • @fd0 - it appears exit was the answer. There appears to be some delay writing to .histfile and exit flushes previous commands to the file. I was conflating the results of my missing .zshrc (which results in no history) with .histfile apparently not being updated. – lx07 Nov 30 '19 at 8:28
  • @MarcWilson - just tried it for fun/curiosity really. I noticed zsh was a changed default in Catalina so thought I'd try it. I don't see much difference from bash that affects me though tbh. – lx07 Nov 30 '19 at 8:35

You must log in to answer this question.

Browse other questions tagged .