Seperate shell history for each terminal window

I have recently upgrade PyCharm and I have lost a feature that I really liked.  In a previous version each terminal window would be keeping its shell history in a separate file.  This was managed by setting the HISTFILE environment variable to a a different value in each terminal window.  These files were in the directory ~/.bash_session. 

What managed that variable and how do I enable that feature again.

Thank you in advance for any assistance.

0
Hi, which version did you upgrade from? This request has been opened for 4 years https://youtrack.jetbrains.com/issue/IDEA-234609/Separate-history-for-each-console-tab
0

It was a version from 2019.  I do not have the actual version anymore.  

0

I have this shell function in my my environment but I am not sure where it came from:
configureCommandHistory () 

   local commandHistoryFile="$__INTELLIJ_COMMAND_HISTFILE__";
   unset __INTELLIJ_COMMAND_HISTFILE__;
   if [ -n "$commandHistoryFile" ] && [ -z "`trap -p EXIT`" ]; then
       trap "$(builtin printf 'history -w %q; HISTFILE=%q' "$commandHistoryFile" "$HISTFILE")" EXIT;
       if [ -s "$commandHistoryFile" ]; then
           HISTFILE="$commandHistoryFile";
       fi;
   fi
}
 

0

I only have that in the PyCharm terminal.  It is not in my other terminal emulators.

0
I see, 2019 is a pretty old version. I'm not sure if anything has changed in regard to the terminal history since then, but at the moment, there's no separate history in 2023.x. Please vote for the request https://youtrack.jetbrains.com/issue/IDEA-234609/Separate-history-for-each-console-tab
0

Maxgusdad 

Based on snippet I have create solution purely in bash. It could (if you want) work for non Jetbrains terminals.
In my case it was enough to distinguish basing on current working directory - so terminal will restore its history depending on directory in which it was opened.

Script:

#!/bin/bash

HISTORY_DIR=/home/$USER/.bash-session/

cleanStr () {
    local a=${1//[^[:alnum:]]/-}
    echo "${a,,}"
}

# history setup
shopt -s histappend

# clean and immediately append new entries
# https://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate/115625#115625
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# detect if the terminal is a JetBrains terminal
if [[ "$TERMINAL_EMULATOR" == "JetBrains-JediTerm" ]]; then
    # create the history directory if it doesn't exist
    if [ ! -d $HISTORY_DIR ]; then
        mkdir $HISTORY_DIR
    fi

    # set the history file
    TERMID=$PWD
    HISTORY_FILENAME=$(cleanStr $TERMID)
    HISTORY_FILEPATH="$HISTORY_DIR$HISTORY_FILENAME"

    echo "JetBrains terminal detected. Configuring command history."
    echo "ID: $HISTORY_FILENAME"

    # configure the command history
    export HISTFILE=$HISTORY_FILEPATH
fi

 

In `~/.bashrc` put `source <path-to-script>` or just put whole script into `.bashrc`

1

请先登录再写评论。