-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1940 from gaelicWizard/history
Feature: automatic history management
- Loading branch information
Showing
7 changed files
with
65 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# shellcheck shell=bash | ||
# | ||
# Functions for working with Bash's command history. | ||
|
||
function _bash-it-history-init() { | ||
safe_append_preexec '_bash-it-history-auto-save' | ||
safe_append_prompt_command '_bash-it-history-auto-load' | ||
} | ||
|
||
function _bash-it-history-auto-save() { | ||
case $HISTCONTROL in | ||
*'noauto'* | *'autoload'*) | ||
: # Do nothing, as configured. | ||
;; | ||
*'auto'*) | ||
# Append new history from this session to the $HISTFILE | ||
history -a | ||
;; | ||
*) | ||
# Append *only* if shell option `histappend` has been enabled. | ||
shopt -q histappend && history -a && return | ||
;; | ||
esac | ||
} | ||
|
||
function _bash-it-history-auto-load() { | ||
case $HISTCONTROL in | ||
*'noauto'*) | ||
: # Do nothing, as configured. | ||
;; | ||
*'autosave'*) | ||
# Append new history from this session to the $HISTFILE | ||
history -a | ||
;; | ||
*'autoloadnew'*) | ||
# Read new entries from $HISTFILE | ||
history -n | ||
;; | ||
*'auto'*) | ||
# Blank in-memory history, then read entire $HISTFILE fresh from disk. | ||
history -a && history -c && history -r | ||
;; | ||
*) | ||
: # Do nothing, default. | ||
;; | ||
esac | ||
} | ||
|
||
_bash_it_library_finalize_hook+=('_bash-it-history-init') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
# shellcheck shell=bash | ||
about-plugin 'eternal bash history' | ||
|
||
# Load after the history plugin | ||
# BASH_IT_LOAD_PRIORITY: 375 | ||
if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then | ||
_log_warning "Bash version 4.3 introduced the 'unlimited' history size capability." | ||
return 1 | ||
fi | ||
|
||
# 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 | ||
readonly HISTSIZE=-1 2> /dev/null || true | ||
|
||
# "Non-numeric values and numeric values less than zero inhibit truncation" | ||
export HISTFILESIZE='unlimited' | ||
readonly HISTFILESIZE='unlimited' 2> /dev/null || true | ||
|
||
# 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" | ||
readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters