Skip to content

Commit

Permalink
Merge pull request #1982 from cornfeedhobo/align-history-plugins
Browse files Browse the repository at this point in the history
Wholesale cleanup of all history plugins
  • Loading branch information
cornfeedhobo authored Dec 2, 2021
2 parents 036cf8a + 2c8ee40 commit 1882f50
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 18 deletions.
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions completion/available/git.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ done
if [[ "${_git_bash_completion_found}" == false ]]; then
_log_warning "no completion files found - please try enabling the 'system' completion instead."
fi
# shellcheck disable=SC2154 # ignore unknown
unset "${!_git_bash_completion@}"
1 change: 1 addition & 0 deletions plugins/available/autojump.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ about-plugin 'Autojump configuration, see https://github.com/wting/autojump for

# Only supports the Homebrew variant, Debian and Arch at the moment.
# Feel free to provide a PR to support other install locations
# shellcheck disable=1090
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then
Expand Down
3 changes: 1 addition & 2 deletions plugins/available/base.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ function usage() {
}

# shellcheck disable=SC2144 # the glob matches only one file
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
# if user has installed todo plugin, skip this...
function t() {
about 'one thing todo'
Expand Down
20 changes: 20 additions & 0 deletions plugins/available/history-eternal.plugin.bash
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 3 additions & 1 deletion plugins/available/history-search.plugin.bash
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion plugins/available/history-substring-search.plugin.bash
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 11 additions & 13 deletions plugins/available/history.plugin.bash
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,19 +11,17 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
# resize history to 100x the default (500)
export HISTSIZE=${HISTSIZE:-50000}

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

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
function top-history() {
about 'print the name and count of the most commonly run tools'

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{
Expand Down
2 changes: 1 addition & 1 deletion vendor/init.d/preexec.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Disable immediate `$PROMPT_COMMAND` modification
__bp_delay_install="delayed"

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

# Block damanaging user's `$HISTCONTROL`
Expand Down

0 comments on commit 1882f50

Please sign in to comment.