Wow, cool! How does this handle the case of multiple shells writing to the history at the same time? I have yet to find a safe way to preserve all that.
# History stuff.
shopt -s histappend
export HISTFILESIZE=50000
export HISTSIZE=50000
export HISTCONTROL=ignoreboth
export PROMPT_COMMAND='history -a'
Individual shells keep their session history in order, while all commands regardless of which shell triggered them get appended to the history file. # infinite history
HOSTNAME="$(hostname)"
HOSTNAME_SHORT="${HOSTNAME%%.*}"
mkdir -p "${HOME}/.history/$(date -u +%Y/%m/)" > /dev/null 2>&1
SESSIONPREFIX=$(date -u +%Y/%m/%d.%H.%M.%S)
export HISTFILE="${HOME}/.history/${SESSIONPREFIX}_${HOSTNAME_SHORT}_$$"
Only thing you're missing is `HISTFILE`, and an alias like alias histgrep='find ~/.history/ -type f -print0 2>/dev/null | xargs -0 grep --color=auto -InH'
https://news.ycombinator.com/item?id=10162189 for contextSo this does not do anything to manage different sessions clobbering each others' histories. The solution posted by zootboy will work together with this script however.