Mac OS terminal tab separate histories

bashterminal

Terminal gets bash to go through an elaborate dance to keep separate histories for each tab. Normally (for me anyway) after a restart of Mac OS these separate histories are lost and you are left with just one.

At one time (years ago) the separate histories survived a reboot (much to my delight) but after yet another OS upgrade it went back to the old behavior.

Over the intervening period I have done sporadic searches trying to find out if I imagined this and what the expected behaviour is but turned up nothing useful.

So, was I imagining this and if not how do I get terminal to preserve individual histories between reboots/logouts?

There is this post which I think addresses the same issue but the answer is bit cryptic for me and it isn't clear where you should add the trap command. Although it may explain why the behaviour comes and goes if that trap is at the in /etc/bashrc_Apple_Terminal and then another OS release comes along without it!

Best Answer

The answer is simple and obvious — i just never thought of it until I did it by accident.

You need to shut down the shell in each tab before you exit terminal. Then when you restart the histories get restored as expected. Shutting down bash causes it to execute the hooks that save the history properly