Hacker News new | ask | show | jobs
by tryauuum 375 days ago
> command I run in one shell session is not immediately available as a history item in other concurrent shell sessions

this can be solved in vanilla bash by adding these lines to .bashrc (be sure to remove other HIST* configs options from it)

    shopt -s histappend
    export HISTSIZE=100000
    export HISTFILESIZE=100000
    export HISTTIMEFORMAT="%F %T "
    export HISTCONTROL=ignoredups:erasedups
    export PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND"
additionally, you need to restart or close all the bash sessions to be sure no copy of bash with old settings exists
1 comments

I recommend a few changes to these:

Infinite history instead of a large limit:

  HISTFILESIZE=-1
  HISTSIZE=-1
Also ignore commands starting with a space:

  HISTCONTROL=ignorespace:ignoredups:erasedups
Enable history substitution to verify commands before running them:

  shopt -s histverify
  shopt -s histreedit
Write commands to history files before running the commands instead of after the commands finish:

  trap 'history -a' DEBUG
Or if you already have a DEBUG trap:

  trap "history -a ; $(trap -p DEBUG | cut -d "'" -f 2)" DEBUG