Durable Shell History
Loren (mcint) January 29, 2023 [Terminal] #cli #bash #config #historyI agree with JeffK's premise in logging shell history.
I've explored a few approaches, and find that I care about locality with better granularity than just time (and host, and working directory).
I like to log shell processes separately. It was almost bearable to have shells dump their history
atomicly to a shared log, and I used things like .bash_logout
, or reached for trap EXIT ...
to
assure this.
However, I've learned over time that I prefer to have files written, in case of a crash,
and that I prefer to use unique HISTFILE
names, instead of allowing a shell without my
custom initialization to start and truncate my carefully grown history.
# ~/.bash_history_rc -> .config/shell/history
# 0->no writes, neg/alpha-> write all
I load the history file through ~/.config/shell/
# ~/.profile
src(){
arg="$1";
arg="$(realpath "$arg")"
if [ -f "$arg" ]; then
. "$arg"
elif [ -d "$arg" ]; then
:;
else
debug "${FUNCNAME[0]}: no file '$1'"
fi
}
src "$HOME/.cargo/env"
for f in ~/.shell/*; do
src "$f";
done
This history file is currently loaded from the ~/.config/shell/
path, but I keep
.bash_history_rc
in the home directory as a form of near, external-memeory. I can
tab complete it at a glance and
While I'm at this, I'll write about other shell config ergonomics