diff --git a/lib/helpers.bash b/lib/helpers.bash index a528c14c0f..ccaa1e7b02 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -837,3 +837,39 @@ then fi } fi + +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 4d6a1b7f51..4eb360c472 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -612,6 +612,6 @@ function safe_append_prompt_command { } 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 }