From 569b8b8c46005aaa260427e720275062dbb8895c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 13:55:50 -0700 Subject: [PATCH] theme/nwinkler: adopt automatic history Use `preexec` and `$HISTCONTROL` to configure _Bash It_'s automatic history management feature. --- themes/nwinkler/nwinkler.theme.bash | 14 ++++++++++++-- .../nwinkler_random_colors.theme.bash | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash index 983c8d00..2f424f6c 100644 --- a/themes/nwinkler/nwinkler.theme.bash +++ b/themes/nwinkler/nwinkler.theme.bash @@ -16,6 +16,18 @@ # since 'fasd' is messing with the $PROMPT_COMMAND +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' + PROMPT_END_CLEAN="${green}→${reset_color}" PROMPT_END_DIRTY="${red}→${reset_color}" @@ -28,8 +40,6 @@ prompt_setter() { if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN else PROMPT_END=$PROMPT_END_DIRTY fi - # Save history - _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash index 05391b0b..16c79448 100644 --- a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash +++ b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash @@ -95,13 +95,23 @@ prompt_setter() { if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN else PROMPT_END=$PROMPT_END_DIRTY fi - # Save history - _save-and-reload-history 1 PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' } +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' + safe_append_prompt_command prompt_setter SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗${normal}"