Skip to content

Commit 8e55cc6

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 3dbaea9 commit 8e55cc6

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/helpers.bash

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,3 +876,44 @@ function _bash-it-find-in-ancestor() (
876876
done
877877
return 1
878878
)
879+
880+
function _bash_it_history_auto_save()
881+
{
882+
case $HISTCONTROL in
883+
*'noauto'*|*'autoload'*)
884+
: # Do nothing, as configured.
885+
;;
886+
*'auto'*)
887+
# Append new history from this session to the $HISTFILE
888+
history -a
889+
;;
890+
*)
891+
# Append *only* if shell option `histappend` has been enabled.
892+
shopt -q histappend && history -a && return
893+
;;
894+
esac
895+
}
896+
897+
function _bash_it_history_auto_load()
898+
{
899+
case $HISTCONTROL in
900+
*'noauto'*)
901+
: # Do nothing, as configured.
902+
;;
903+
*'autosave'*)
904+
# Append new history from this session to the $HISTFILE
905+
history -a
906+
;;
907+
*'autoloadnew'*)
908+
# Read new entries from $HISTFILE
909+
history -n
910+
;;
911+
*'auto'*)
912+
# Blank in-memory history, then read entire $HISTFILE fresh from disk.
913+
history -a && history -c && history -r
914+
;;
915+
*)
916+
: # Do nothing, default.
917+
;;
918+
esac
919+
}

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)