5

I want to keep history separated for each tab (even for split windows within one tab). I therefore found a solution to add these two lines after source $ZSH/oh-my-zsh.sh:

source $ZSH/oh-my-zsh.sh unsetopt inc_append_history unsetopt share_history 

Now the history is really separated, nevertheless when I completely close the terminal (in my case Tabby), the histories for each tab are common again. How to solve that? I use zsh with Tabby.

1
  • I wanted permanent history to be shared, but running tabs to stay separate. This question answered that for me. I use the built-in macOS Terminal. Thank you! Commented Apr 3, 2024 at 14:16

2 Answers 2

1

If you want each session to keep a separate history, then you will need to do one of the following:

  • If you do not want history to be saved to file, then simply unset $HISTFILE in your .zshrc file after sourcing OMZ:

    source $ZSH/oh-my-zsh.sh unsetopt inc_append_history share_history unset HISTFILE 

    Then each new shell session will start with an empty history.

  • If you do want to save history for each session, then you will need to set a different $HISTFILE for each session in your .zshrc file before you source OMZ. If your terminal sets a unique ID for each terminal session (I don't know if Tabby does that), like $TERM_SESSION_ID, then you can do something like this:

    mkdir -m 700 -p ${SHELL_SESSION_DIR:=${ZDOTDIR:-$HOME}/.zsh_sessions} HISTFILE=$SHELL_SESSION_DIR/$TERM_SESSION_ID.history source $ZSH/oh-my-zsh.sh unsetopt inc_append_history share_history unset HISTFILE 

    If your terminal persists the $TERM_SESSION_ID for each tab between restarts, then the individual history for each tab will be restored whenever you reopen them.

6
  • Can u tel me exactly where to define such change? Commented May 11, 2022 at 5:05
  • i tried like this but doesnt work: source $ZSH/oh-my-zsh.sh setopt noincappendhistory unsetopt nosharehistory unsetopt appendhistory Commented May 11, 2022 at 5:10
  • Like I said, you need to set the $HISTFILE parameter. Commented May 16, 2022 at 6:00
  • how exactly, can u put as an asnwer? Commented May 18, 2022 at 10:17
  • For this to work, you will need to have a unique ID that persists between restarts for each tab. Does tabby have an environment variable you can use for this? I don’t use Tabby myself. Commented May 18, 2022 at 14:39
0

The only way which worked for me with Tabby is to add the following in the .zshrc file:

if [[ -n "$TABBY_HISTFILE" ]]; then export HISTFILE="$TABBY_HISTFILE" fi 

Then in each Tabby profile set the path for a separate history file by adding a TABBY_HISTFILE environment variable.

For example:

TABBY_HISTFILE = /Users/<username>/TabbyHistory/.zsh_history_profile_a 

Make sure to re-open the profile in Tabby and run fc -W to force write the new history file.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.