7

I found it irritating that if you run one command 5 times you have to press the arrow key 6 times to get the previous command. Is it some way to change this behavior?

iTerm2 Build 1.0.0.20111020

bandola
  • 267
  • 1
  • 3
  • 13

1 Answers1

8

That's not a feature of iTerm but of your shell's history feature. If you use the default Bash you can put this into your ~/.bashrc:

export HISTCONTROL=ignoreboth
shopt -s histappend
# After each command, save and reload history
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

The first line will tell Bash to ignore duplicated and empty history entries. The second line will merge the history of multiple open sessions (e.g. in multiple tabs or windows). The thirs line will make sure that the history is preserved after each command.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
  • Thanks a lot! You have changed my life : ) – bandola Jan 15 '12 at 23:06
  • 1
    Many people have their dotfiles collection (of which the .bashrc is one) on GitHub. There are often many useful gems in there. Just google for "github dotfiles" and start browsing. – Holger Just Jan 15 '12 at 23:09
  • I have added a few alias so far but now a hole new world opens up, thanks again! – bandola Jan 15 '12 at 23:21
  • I don't know why, but my iTerm never loads bashrc. I had to put the lines in my bash_profile instead. But thanks, this was exactly what I was looking for!! :D – NHDaly Apr 28 '13 at 19:27