From db04b2b29f74eb3bbbcc14f8c2d2d4ed6ad0a885 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 13:56:20 -0700 Subject: [PATCH] theme/doubletime: adopt automatic history Use `preexec` and `$HISTCONTROL` to configure _Bash It_'s automatic history management feature. --- themes/doubletime/doubletime.theme.bash | 14 ++++++++++++-- .../doubletime_multiline.theme.bash | 14 ++++++++++++-- .../doubletime_multiline_pyonly.theme.bash | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash index 8186db73..536573e4 100644 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -1,5 +1,17 @@ # shellcheck shell=bash +case $HISTCONTROL in +*'auto'*) + : # Do nothing, already configured. + ;; +*) + # Append new history lines to history file + HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autosave" + ;; +esac +safe_append_preexec '_bash-it-history-auto-load' +safe_append_prompt_command '_bash-it-history-auto-save' + SCM_THEME_PROMPT_DIRTY='' SCM_THEME_PROMPT_CLEAN='' SCM_GIT_CHAR="${bold_cyan}±${normal}" @@ -29,8 +41,6 @@ else fi function prompt_setter() { - # Save history - _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w $(scm_prompt)$reset_color $ " diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash index f2dfe43a..8b2bab04 100644 --- a/themes/doubletime_multiline/doubletime_multiline.theme.bash +++ b/themes/doubletime_multiline/doubletime_multiline.theme.bash @@ -2,9 +2,19 @@ source "$BASH_IT/themes/doubletime/doubletime.theme.bash" +case $HISTCONTROL in +*'auto'*) + : # Do nothing, already configured. + ;; +*) + # Append new history lines to history file + HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autosave" + ;; +esac +safe_append_preexec '_bash-it-history-auto-load' +safe_append_prompt_command '_bash-it-history-auto-save' + function prompt_setter() { - # Save history - _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt) \w diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash index 0fe0eff4..a2a5884c 100644 --- a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash +++ b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash @@ -2,9 +2,19 @@ source "$BASH_IT/themes/doubletime/doubletime.theme.bash" +case $HISTCONTROL in +*'auto'*) + : # Do nothing, already configured. + ;; +*) + # Append new history lines to history file + HISTCONTROL="${HISTCONTROL:-}${HISTCONTROL:+:}autosave" + ;; +esac +safe_append_preexec '_bash-it-history-auto-load' +safe_append_prompt_command '_bash-it-history-auto-save' + function prompt_setter() { - # Save history - _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt) \w