Skip to content

Commit

Permalink
lib/helpers: new functions _bash_it_history_auto_*()
Browse files Browse the repository at this point in the history
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 Bash-it#1595 for discussion.

# Conflicts:
#	lib/helpers.bash
#	themes/base.theme.bash
  • Loading branch information
gaelicWizard committed Feb 9, 2022
1 parent 0353916 commit 1e4a2ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1e4a2ef

Please sign in to comment.