From 66708ddc83ead7f9fac53ee6e6769c7d4a5d6f9e Mon Sep 17 00:00:00 2001
From: John D Pell <John+git@gaelicWizard.net>
Date: Fri, 10 Sep 2021 13:56:34 -0700
Subject: [PATCH] theme/codeword: adopt automatic history

Use `preexec` and `$HISTCONTROL` to configure _Bash It_'s automatic history management feature.
---
 themes/codeword/codeword.theme.bash | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash
index beab6a4a79..48128fa4f9 100644
--- a/themes/codeword/codeword.theme.bash
+++ b/themes/codeword/codeword.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_PREFIX=${SCM_THEME_PROMPT_SUFFIX}
 SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}"
 SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}"
@@ -21,5 +33,4 @@ prompt() {
   PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) "
 }
 
-safe_append_prompt_command '_save-and-reload-history 1'
 safe_append_prompt_command prompt