39

I am using iTerm2 (with zsh), and for some reason the history is shared between the different tabs and windows that are open. In most of the cases for me, this is annoying, since I have tabs per specific task, and if I have to redo some commands, I just want to be able to go back (up) in history to retrieve the last action for that window/tab only.

I have no idea how to disable this shared history, I read somewhere that you can enable shared history in zsh, but afaik I have done no such thing.

Can anybody point me in the right direction?

2 Answers 2

49

Executing the following should do the trick (use setopt to reenable them):

unsetopt inc_append_history
unsetopt share_history
8
  • 3
    Do I add these to my .zshrc?
    – nathanvda
    Commented Dec 21, 2012 at 11:04
  • 1
    and with bash???
    – nkint
    Commented Jan 22, 2013 at 21:31
  • 3
    @nathanvda yep, you add this to .zshrc. Commented Jan 27, 2015 at 3:00
  • 1
    What about bash shell?
    – A.D
    Commented Jul 14, 2016 at 16:03
  • 4
    I am getting -bash: unsetopt: command not found. Is it possible that this is something tmux related? Afaik I am not using tmux, but I am still experiencing the same problem as OP Commented Oct 18, 2016 at 16:26
0

For me above mentioned commands didn't work.

I am using plain ZSH, not Oh-my-zsh.

Here's what worked for me (./zshrc):

export HISTFILE="$HOME/.zsh_sessions/history_$TERM_SESSION_ID" # use a different histfile per shell
setopt INC_APPEND_HISTORY # new history lines are added to the file as soon as they are entered (not after terminal is closed)
if [ ! -e $HISTFILE ]; then cp "$HOME/.zsh_sessions/$(ls -Art $HOME/.zsh_sessions | tail -n 1)" "$HISTFILE"; fi # for new shells, initialize history with the history of the most recently used shell

You must log in to answer this question.

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