theme/nwinkler: adopt automatic history

Use `preexec` and `$HISTCONTROL` to configure _Bash It_'s automatic history management feature.
pull/1951/head
John D Pell 2021-09-10 13:55:50 -07:00 committed by John D Pell
parent 7823e36d15
commit 569b8b8c46
2 changed files with 24 additions and 4 deletions

View File

@ -16,6 +16,18 @@
# since 'fasd' is messing with the $PROMPT_COMMAND # 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_CLEAN="${green}${reset_color}"
PROMPT_END_DIRTY="${red}${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 if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN
else PROMPT_END=$PROMPT_END_DIRTY else PROMPT_END=$PROMPT_END_DIRTY
fi 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) " 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='> ' PS2='> '
PS4='+ ' PS4='+ '

View File

@ -95,13 +95,23 @@ prompt_setter() {
if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN
else PROMPT_END=$PROMPT_END_DIRTY else PROMPT_END=$PROMPT_END_DIRTY
fi 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) " 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='> ' PS2='> '
PS4='+ ' 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 safe_append_prompt_command prompt_setter
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}" SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"