plugin/history-eternal: Use `readonly` instead of `export`

...and hide errors relating to setting already-readonly variables.

`plugin/history-eternal` does not need to force loading after `plugin/history` because both plugins will play nicely with read-only variables, and since we're overwritting and marking read-only then the intended result survives no matter which loads first.

plugin/history-eternal: require Bash v4.3+

Unlimited history is only possible in _Bash_ version 4.3 and up
pull/1940/head
John D Pell 2021-12-27 14:21:44 -08:00 committed by John D Pell
parent 8052911861
commit 267a721ac6
1 changed files with 7 additions and 5 deletions

View File

@ -1,20 +1,22 @@
# shellcheck shell=bash # shellcheck shell=bash
about-plugin 'eternal bash history' about-plugin 'eternal bash history'
# Load after the history plugin if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
# BASH_IT_LOAD_PRIORITY: 375 _log_warning "Bash version 4.3 introduced the 'unlimited' history size capability."
return 1
fi
# Modify history sizes before changing location to avoid unintentionally # Modify history sizes before changing location to avoid unintentionally
# truncating the history file early. # truncating the history file early.
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)" # "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" # "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 # Use a custom history file location so history is not truncated
# if the environment ever loses this "eternal" configuration. # if the environment ever loses this "eternal" configuration.
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash" HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}" [[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
export HISTFILE="${HISTDIR?}/history" readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true