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 }