zsh history not preserved in Terminal

I got a new MacBook Pro which came with Catalina pre-installed.  In Catalina, Apple apparently decided zsh should be what people use instead of bash.  So I gave in and switched to zsh because I hear good things about zsh anyway.

After resolving all the path issues caused by .bash_profile not being used, all seemed well.  However, I notice that WebStorm does not save any Terminal history.  If I close the terminal tab and restart Terminal, no history is present.  However, as long as the terminal tab is opened, history is being preserved.

This is not happening with the MacOS Terminal and as far as I can tell is only happening in the JetBrains Terminal tool. I also checked IDEA 2019.3.1 and it seems to be the same.

Am I missing some step to get history to save between Terminal tool sessions?

Setup:

WebStorm 2019.3.1
Build #WS-193.5662.54, built on December 17, 2019
...
Runtime version: 11.0.5+10-b520.17 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.2
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry: ide.balloon.shadow.size=0
Non-Bundled Plugins: com.github.beansoftapp.reatnative.idea, com.intellij.lang.jsgraphql, com.intellij.react.css.modules, com.jinsihou.react.snippets, com.suming.react.PropTypes, com.vladsch.idea.multimarkdown, com.wix.eslint, in.oneton.contrib.plugin.angular.material, org.toml.lang

1
4 comments

Does it only happen when using zsh?

Also, does disabling Shell integration in Preferences | Tools | Terminal make things any better?

1

With "Shell integration in Preferences | Tools | Terminal" enabled and the terminal open, running

echo $HISTFILE

gave me this path

/Applications/PhpStorm 2020.1 EAP.app/Contents/plugins/terminal/.zsh_history

So I disabled "Shell integration" and "$HISTFILE" resolved to my default path

/Users/username/.zsh_history

This gives me my full history back.

Having now read that the plugin "first loads a custom rc config file" I have now added this to my .zshrc file:

export HISTFILE=$HOME/.zsh_history

I believe this overrides whatever the plugin is doing and gives me my full history with the "Shell integration" setting enabled.

10

Thanks @Stephen ^

Interesting, this actually finally makes sense why my zsh_history misses things I have done inside the IDE.

The `HISTFILE` export thing would be the way to keep the "Shell Integration" plugin enabled, however, disabling this (what does it even do other than chroot you into

/Applications/PhpStorm 2020.1 EAP.app/Contents/plugins/terminal/

?! ;-)

0

Hi Stephen
The solution you suggested works, but it seems to be working one way. 

(I can see shell history in the integrated shell, but not the other way round. And the integrated shell history gets lost when the terminal is closed.)

Any suggestions to fix this ?

2

Please sign in to leave a comment.