Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When I restart my Mac it quits and saves the buffers for each tab properly, since it's there again when the computer starts back up. But the command history is not buffered properly per window/tab. They're all the same buffer.

I'm assuming it's because bash uses the same ~/.bash_history for all terminals but is there a way to avoid improve this? To make bash, or maybe Terminal, store them separately?

share|improve this question
    
Please see this post @ Server Fault, it explains how to do this. –  Mutant Feb 21 '12 at 16:30
add comment

2 Answers

up vote 2 down vote accepted

You could do something like this in your .bashrc:

MYTTY=`tty`
HISTFILE=$HOME/.bash_history_`basename $MYTTY`

This will create separate history files in your home directory such as .bash_history_ttys002. When you create a new terminal window, it will use the history file corresponding to the tty name, which will usually be determined simply by the order in which you create the terminal windows.

share|improve this answer
    
Great, thanks! Marking this as solved. Even though it kind of depends on how OSX loads the terminals I have a feeling this is the closest we can get. –  Robert Sköld Feb 27 '12 at 13:23
    
Is this also possible per-tab?? –  Joshua Muheim Mar 5 at 7:58
    
Each tab is a separate tty login, so it should work. –  Seth Noble Mar 5 at 19:20
add comment

You can set a custom $HISTFILE for each of you Terminal instances.

share|improve this answer
    
Is there a way to do this automatically for each Terminal tab/window? And make sure it's using the same $HISTFILE when the computer starts back up? –  Robert Sköld Feb 20 '12 at 13:47
1  
Yes, it's possible to do this, but then how would you access again? You'd manually have to juggle files to get to the previous history files. –  EmmEff Feb 20 '12 at 14:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.