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.
  • Loading branch information
gaelicWizard committed Sep 10, 2021
1 parent 9ea6002 commit 8d1475c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
36 changes: 36 additions & 0 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 4 additions & 3 deletions themes/base.theme.bash
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ function safe_append_prompt_command {
fi
}

function _save-and-reload-history() {
local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
function _save-and-reload-history()
{
[[ ${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 8d1475c

Please sign in to comment.