Skip to content

Commit 0103762

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 9ea6002 commit 0103762

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/helpers.bash

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,39 @@ then
837837
fi
838838
}
839839
fi
840+
841+
function _bash_it_history_auto_save()
842+
{
843+
case $HISTCONTROL in
844+
*'noauto'*|*'autoload'*)
845+
: # Do nothing, as configured.
846+
;;
847+
*'auto'*)
848+
# Append new history from this session to the $HISTFILE
849+
history -a
850+
;;
851+
*)
852+
: # Do nothing, default.
853+
;;
854+
esac
855+
}
856+
857+
function _bash_it_history_auto_load()
858+
{
859+
case $HISTCONTROL in
860+
*'noauto'*|*'autosave'*)
861+
: # Do nothing, as configured.
862+
;;
863+
*'autoloadnew'*)
864+
# Read new entries from $HISTFILE
865+
history -n
866+
;;
867+
*'auto'*)
868+
# Blank in-memory history, then read entire $HISTFILE fresh from disk.
869+
history -c && history -r
870+
;;
871+
*)
872+
: # Do nothing, default.
873+
;;
874+
esac
875+
}

themes/base.theme.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,6 @@ function safe_append_prompt_command {
612612
}
613613

614614
function _save-and-reload-history() {
615-
local autosave=${1:-0}
616-
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
615+
[[ ${1:-${autosave:-${HISTORY_AUTOSAVE:-0}}} -eq 1 ]] && local HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autoshare"
616+
_bash_it_history_auto_save && _bash_it_history_auto_load
617617
}

0 commit comments

Comments
 (0)