1

I've got an annoying problem with iterm2 not remembering my history when I close out a terminal window. I'm not sure if it might be my .bash_profile config or what.

Here is what is happening:

1) type in some commands
2) issue `history` command
3) commands are listed
4) close terminal window and open brand new terminal window
5) issue `history` command
6) commands from previous sessions are NOT listed
7) close terminal window and open brand new terminal window
6) issue `history` command
7) commands from very first session now appearing

Anyone know why the previous commands aren't showing up right away when a new window is opened and only after a second terminal window is opened?

UPDATE: Everything works as expected with the plain old terminal app.

Update 2: I have the shell integration feature installed

Update 3: It turns out the first update was incorrect. It is also flaky on Terminal. Sometimes it will work and other times it doesn't.

5
  • What happens when you exit the shell before closing the window?
    – fd0
    Commented Aug 18, 2018 at 15:02
  • If I type in the "exit" command, it works properly.
    – StevieD
    Commented Aug 18, 2018 at 15:19
  • Try adding SHELL_SESSION_HISTORY=0 to your ~/.bash_profile file, quite the Terminal/iTerm2 App and reopen, test again. Commented Aug 18, 2018 at 20:11
  • Yeah, I've done that for now until I can get the problem resolved.
    – StevieD
    Commented Aug 18, 2018 at 20:27
  • Editing ~/.bash_profile with SHELL_SESSION_HISTORY didn't do anything. The problem was .bash_history having permissions -rw------- root staff as set by /etc/bashrc_Apple_Terminal. Little bit of chowning solved it. Now history works with iTerm2. Commented Jun 2, 2020 at 10:52

2 Answers 2

2

So it turns out iterm was actually working in iterm. It just waits 5 seconds before saving to .bash_history when you close out of a shell without using the exit command. This 5 second delay is to give you time to command-z the session back open, apparently.

0

Sorry for the double posting from 218731.
For me the solution was more hidden, yet easier to resolve.
By looking at the extended attribute of my .bash_history file and .bash_sessions content, I found out it had these attributes disallowing me to write despite the normal permissions:

$ ls -le .bash_history
-rw-r--r--@   1 XXX  staff  14484  2 Aug 17:04 .bash_history
 0: group:everyone deny write,delete,append,writeattr,writeextattr,chown

The same if running ls -lea .bash_sessions.
The solution was "simply":

chmod -R -a# 0 .bash_sessions/ .bash_history
1
  • This doesn’t address the iTerm issue raised in the question.
    – Allan
    Commented Jan 13, 2023 at 13:42

You must log in to answer this question.

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