Skip to content

Commit 1882f50

Browse files
authored
Merge pull request #1982 from cornfeedhobo/align-history-plugins
Wholesale cleanup of all history plugins
2 parents 036cf8a + 2c8ee40 commit 1882f50

File tree

9 files changed

+42
-18
lines changed

9 files changed

+42
-18
lines changed

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ plugins/available/docker-machine.plugin.bash
9292
plugins/available/git.plugin.bash
9393
plugins/available/go.plugin.bash
9494
plugins/available/goenv.plugin.bash
95+
plugins/available/history-eternal.plugin.bash
9596
plugins/available/history-search.plugin.bash
9697
plugins/available/history-substring-search.plugin.bash
9798
plugins/available/history.plugin.bash

completion/available/git.completion.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ done
3939
if [[ "${_git_bash_completion_found}" == false ]]; then
4040
_log_warning "no completion files found - please try enabling the 'system' completion instead."
4141
fi
42+
# shellcheck disable=SC2154 # ignore unknown
4243
unset "${!_git_bash_completion@}"

plugins/available/autojump.plugin.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ about-plugin 'Autojump configuration, see https://github.com/wting/autojump for
44

55
# Only supports the Homebrew variant, Debian and Arch at the moment.
66
# Feel free to provide a PR to support other install locations
7+
# shellcheck disable=1090
78
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
89
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
910
elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then

plugins/available/base.plugin.bash

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ function usage() {
121121
}
122122

123123
# shellcheck disable=SC2144 # the glob matches only one file
124-
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
125-
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
124+
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
126125
# if user has installed todo plugin, skip this...
127126
function t() {
128127
about 'one thing todo'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# shellcheck shell=bash
2+
about-plugin 'eternal bash history'
3+
4+
# Load after the history plugin
5+
# BASH_IT_LOAD_PRIORITY: 375
6+
7+
# Modify history sizes before changing location to avoid unintentionally
8+
# truncating the history file early.
9+
10+
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
11+
export HISTSIZE=-1
12+
13+
# "Non-numeric values and numeric values less than zero inhibit truncation"
14+
export HISTFILESIZE='unlimited'
15+
16+
# Use a custom history file location so history is not truncated
17+
# if the environment ever loses this "eternal" configuration.
18+
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
19+
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
20+
export HISTFILE="${HISTDIR?}/history"

plugins/available/history-search.plugin.bash

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'search history using the prefix already entered'
43

4+
# Load after the history plugin
5+
# BASH_IT_LOAD_PRIORITY: 375
6+
57
# enter a few characters and press UpArrow/DownArrow
68
# to search backwards/forwards through the history
79
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

plugins/available/history-substring-search.plugin.bash

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'search history using the substring already entered'
43

4+
# Load after the history plugin
5+
# BASH_IT_LOAD_PRIORITY: 375
6+
57
# enter a few characters and press UpArrow/DownArrow
68
# to search backwards/forwards through the history
79
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

plugins/available/history.plugin.bash

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'improve history handling with sane defaults'
43

5-
# append to bash_history if Terminal.app quits
4+
# Append the history list to the file named by the value of the HISTFILE
5+
# variable when the shell exits, rather than overwriting the file.
66
shopt -s histappend
77

88
# erase duplicates; alternative option: export HISTCONTROL=ignoredups
@@ -11,19 +11,17 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
1111
# resize history to 100x the default (500)
1212
export HISTSIZE=${HISTSIZE:-50000}
1313

14-
top-history() {
15-
about 'print the name and count of the most commonly run tools'
14+
# Flush history to disk after each command.
15+
export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
1616

17-
if [[ -n $HISTTIMEFORMAT ]]; then
18-
# To parse history we need a predictable format, which HISTTIMEFORMAT
19-
# gets in the way of. So we unset it and set a trap to guarantee the
20-
# user's environment returns to normal even if the pipeline below fails.
21-
# shellcheck disable=SC2064
22-
trap "export HISTTIMEFORMAT='$HISTTIMEFORMAT'" RETURN
23-
unset HISTTIMEFORMAT
24-
fi
17+
function top-history() {
18+
about 'print the name and count of the most commonly run tools'
2519

26-
history \
20+
# - Make sure formatting doesn't interfer with our parsing
21+
# - Use awk to count how many times the first command on each line has been called
22+
# - Truncate to 10 lines
23+
# - Print in column format
24+
HISTTIMEFORMAT='' history \
2725
| awk '{
2826
a[$2]++
2927
}END{

vendor/init.d/preexec.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Disable immediate `$PROMPT_COMMAND` modification
99
__bp_delay_install="delayed"
1010

11-
# shellcheck source-path=SCRIPTDIR/../github.com/rcaloras/bash-preexec
11+
# shellcheck source=SCRIPTDIR/../github.com/rcaloras/bash-preexec
1212
source "${BASH_IT?}/vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh"
1313

1414
# Block damanaging user's `$HISTCONTROL`

0 commit comments

Comments
 (0)