bash-preexec
bash-preexec copied to clipboard
Check to make sure History is enabled.
Several history features should be checked or enabled to make sure bash-preexec can operate correctly.
One example is simply making sure history is turned on.
history_check=$(set -o | grep history)
if [[ "$history_check" == "history off" ]]; then
echo "Enable history to use bash preexec"
return 1
fi;
Quoted by @evverx on #6 :
@rcaloras , thanks. Could probably add a few more checks to make sure history is properly enabled
Too many checks: history on
, HISTSIZE
, history-size
in ~/.inputrc
...
I vote for auto enabling:)
I've collected some useful settings:
# enable access to the command history
set -o history
# save each line of a multi-line command in the same history entry
shopt -s cmdhist
# save the command with embedded newlines instead of semicolons
shopt -s lithist
# save lines which begin with a space character in the history list
# preserve dups!
HISTCONTROL= # already done
# save all lines in the history list
HISTIGNORE=
# every command being saved on the history list (there is no limit)
HISTSIZE=-1
bind 'set history-size -1'
See also: my bulletproof history collector :)
What about if HISTCONTROL or HISTTIMEFORMAT is already set and a user has scripts that need those already set settings? I didn't see anything in the README that says it will overwrite user defined settings. I just found this repo and didn't look closely enough if it will check before overwriting but I don't think it checks.
I vote very much against automatically and silently changing user settings. If a condition can't be worked around, then warn loudly before tweaking.
@rcaloras, is the purpose of the history check specifically just to make sure preexec runs once-per-interactive-line (rather than DEBUG per simple command)?
I answered my own question by re-rereading and I have a separate PR open, so please disregard my comments here.