recentpopularlog in

Copy this bookmark:





to read

bookmark detail

Preserve bash history in multiple terminal windows - Unix & Linux Stack Exchange
True dat:
@Oli wrote, "I can't think of an intelligent way to do it where existing terminals only see their own history but new ones see a chronologically accurate list of commands." How about (untried): export PROMPT_COMMAND="history -a; $PROMPT_COMMAND". Existing shells will add each command to the history file for new shells to see, but only show their own histories.


Many solutions proposed, all with caveats, but this is what I decided on:

<code class="language-bash">
HISTCONTROL=ignoredups:erasedups # no duplicate entries
HISTSIZE=100000 # big big history
HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite

# append current history list to the history file after each command finishes
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"</code>

This appends lines to the history file after each command, which makes them available in other sessions, but up arrow will still reverse through the history only for the current session, which is probably less confusing.

You can bring in commands from other sessions (which have been written to the history file) with 'history -n'. Depending on the setting of 'HISTCONTROL', these might end up getting written out to the history file again, though. ¯\_(ツ)_/¯
bash  history  histfile  historyexpansion  frustration  configfile  forthecomments  solution 
july 2019 by kme
view in context