From 1e4a2efcbd13b6df38965f18990a9abfb26ddfd3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 18 Oct 2021 10:33:30 -0400 Subject: [PATCH] lib/helpers: new functions `_bash_it_history_auto_*()` Two new functions `_bash_it_history_auto_save()` and `_bash_it_history_auto_load()`, which append new history to disk and load new history from disk, respectively. See bash-it/bash-it#1595 for discussion. # Conflicts: # lib/helpers.bash # themes/base.theme.bash --- lib/helpers.bash | 36 ++++++++++++++++++++++++++++++++++++ themes/base.theme.bash | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 2601829d73..14e753dcfd 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1038,3 +1038,39 @@ function _bash-it-find-in-ancestor() ( done return 1 ) + +function _bash_it_history_auto_save() +{ + case $HISTCONTROL in + *'noauto'*|*'autoload'*) + : # Do nothing, as configured. + ;; + *'auto'*) + # Append new history from this session to the $HISTFILE + history -a + ;; + *) + : # Do nothing, default. + ;; + esac +} + +function _bash_it_history_auto_load() +{ + case $HISTCONTROL in + *'noauto'*|*'autosave'*) + : # Do nothing, as configured. + ;; + *'autoloadnew'*) + # Read new entries from $HISTFILE + history -n + ;; + *'auto'*) + # Blank in-memory history, then read entire $HISTFILE fresh from disk. + history -c && history -r + ;; + *) + : # Do nothing, default. + ;; + esac +} diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a78341bdc3..521335142c 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -583,6 +583,6 @@ function aws_profile() { } function _save-and-reload-history() { - local autosave=${1:-0} - [[ $autosave -eq 1 ]] && history -a && history -c && history -r + [[ ${1:-${autosave:-${HISTORY_AUTOSAVE:-0}}} -eq 1 ]] && local HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autoshare" + _bash_it_history_auto_save && _bash_it_history_auto_load }