Skip to content

Commit a2d579e

Browse files
committed
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 #1595 for discussion.
1 parent d6c4c0c commit a2d579e

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

lib/helpers.bash

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,3 +849,40 @@ then
849849
fi
850850
}
851851
fi
852+
853+
function _bash_it_history_auto_save()
854+
{
855+
case $HISTCONTROL in
856+
*'noauto'*|*'autoload'*)
857+
: # Do nothing, as configured.
858+
;;
859+
*'auto'*)
860+
# Append new history from this session to the $HISTFILE
861+
history -a
862+
;;
863+
*)
864+
# Append *only* if shell option `histappend` has been enabled.
865+
shopt -q histappend && history -a && return
866+
;;
867+
esac
868+
}
869+
870+
function _bash_it_history_auto_load()
871+
{
872+
case $HISTCONTROL in
873+
*'noauto'*|*'autosave'*)
874+
: # Do nothing, as configured.
875+
;;
876+
*'autoloadnew'*)
877+
# Read new entries from $HISTFILE
878+
history -n
879+
;;
880+
*'auto'*)
881+
# Blank in-memory history, then read entire $HISTFILE fresh from disk.
882+
history -a && history -c && history -r
883+
;;
884+
*)
885+
: # Do nothing, default.
886+
;;
887+
esac
888+
}

themes/base.theme.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,6 @@ function safe_append_prompt_command {
620620
}
621621

622622
function _save-and-reload-history() {
623-
local autosave=${1:-0}
624-
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
623+
[[ ${1:-${autosave:-${HISTORY_AUTOSAVE:-0}}} -eq 1 ]] && local HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autoshare"
624+
_bash_it_history_auto_save && _bash_it_history_auto_load
625625
}

0 commit comments

Comments
 (0)