Wholesale cleanup of all history plugins

- remove the use of redundant cite
- minor cleanups to history.plugin.bash
- set explicit load orders for history-search and history-substring-search
- add new plugin history-eternal
- replace superfluous trap for managing HISTTIMEFORMAT changes
pull/1982/head
cornfeedhobo 2021-11-01 22:26:50 -05:00
parent 036cf8ada0
commit bdb5289660
No known key found for this signature in database
GPG Key ID: 724357093F994B26
5 changed files with 38 additions and 15 deletions

View File

@ -92,6 +92,7 @@ plugins/available/docker-machine.plugin.bash
plugins/available/git.plugin.bash
plugins/available/go.plugin.bash
plugins/available/goenv.plugin.bash
plugins/available/history-eternal.plugin.bash
plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash

View File

@ -0,0 +1,20 @@
# shellcheck shell=bash
about-plugin 'eternal bash history'
# Load after the history plugin
# BASH_IT_LOAD_PRIORITY: 375
# Modify history sizes before changing location to avoid unintentionally
# truncating the history file early.
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
export HISTSIZE=-1
# "Non-numeric values and numeric values less than zero inhibit truncation"
export HISTFILESIZE='unlimited'
# Use a custom history file location so history is not truncated
# if the environment ever loses this "eternal" configuration.
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
export HISTFILE="${HISTDIR?}/history"

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'search history using the prefix already entered'
# Load after the history plugin
# BASH_IT_LOAD_PRIORITY: 375
# enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'search history using the substring already entered'
# Load after the history plugin
# BASH_IT_LOAD_PRIORITY: 375
# enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

View File

@ -1,8 +1,8 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'improve history handling with sane defaults'
# append to bash_history if Terminal.app quits
# Append the history list to the file named by the value of the HISTFILE
# variable when the shell exits, rather than overwriting the file.
shopt -s histappend
# erase duplicates; alternative option: export HISTCONTROL=ignoredups
@ -11,19 +11,17 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
# resize history to 100x the default (500)
export HISTSIZE=${HISTSIZE:-50000}
top-history() {
# Flush history to disk after each command.
export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
function top-history() {
about 'print the name and count of the most commonly run tools'
if [[ -n $HISTTIMEFORMAT ]]; then
# To parse history we need a predictable format, which HISTTIMEFORMAT
# gets in the way of. So we unset it and set a trap to guarantee the
# user's environment returns to normal even if the pipeline below fails.
# shellcheck disable=SC2064
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN
unset HISTTIMEFORMAT
fi
history \
# - Make sure formatting doesn't interfer with our parsing
# - Use awk to count how many times the first command on each line has been called
# - Truncate to 10 lines
# - Print in column format
HISTTIMEFORMAT='' history \
| awk '{
a[$2]++
}END{