5

I'm using Mac 10.9.5. When I run a terminal with multiple tabs (using bash shell), I've noticed that when my computer restarts, the terminal will open up with the same number of tabs that were open in the previous session, but the commands I was running in the previous session (accessible via the "history" shell command) are no longer present in each tab.

Is there a way to preserve each session's history in the appropriate tab between computer restarts?

0

3 Answers 3

1

Try adding this to ~/.bash_profile:

HISTFILE=~/.bash_history.$(basename $(tty))

This creates a unique history file for the terminal associated with each tab.

1
  • Already covered here.
    – mtklr
    Commented Jul 7, 2015 at 2:23
0

This worked for me:

  1. Disable Settings:Desktop & Dock:"Close windows when quitting an application". (This setting seems to move around with each OS version)

  2. Quit Terminal, using command Q while the window is still open.

  3. Restart Terminal, the window reopens, and tabs are restored with individual histories.

enter image description here

-2

The command history is saved by the shell when it closes, and by default this goes into ~/.bash_history.

So as the shell in each of your tabs is closed, they each append their own command history to that file. When new shells/tabs are opened, they will load that file for their history.

So in a sense, each tab's history is saved, and you should be able to use ctrl-R to search for it (within limits of the history size limit), but when reloaded, each tab will see all the history, and in blocks corresponding to the order the previous tabs happened to close.

You might be able to configure the bash history more to your liking.

1
  • 1
    The answer should be based around the information in the link telling the OP how to preserver the session's history. The other info is a good explanation of what the history does but does not answer the question asked
    – mmmmmm
    Commented Jul 6, 2015 at 21:32

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