Skip to content

Commit 1f87478

Browse files
committed
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
1 parent 2e3fe4a commit 1f87478

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
# shellcheck shell=bash
22
about-plugin 'eternal bash history'
33

4-
# Load after the history plugin
5-
# BASH_IT_LOAD_PRIORITY: 375
4+
if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
5+
_log_warning "Bash version 4.3 introduced the 'unlimited' history size capability."
6+
return 1
7+
fi
68

79
# Modify history sizes before changing location to avoid unintentionally
810
# truncating the history file early.
911

1012
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
11-
export HISTSIZE=-1
13+
readonly HISTSIZE=-1 2> /dev/null
1214

1315
# "Non-numeric values and numeric values less than zero inhibit truncation"
14-
export HISTFILESIZE='unlimited'
16+
readonly HISTFILESIZE='unlimited' 2> /dev/null
1517

1618
# Use a custom history file location so history is not truncated
1719
# if the environment ever loses this "eternal" configuration.
1820
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
1921
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
20-
export HISTFILE="${HISTDIR?}/history"
22+
readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null

0 commit comments

Comments
 (0)