-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: automatic history management #1940
Conversation
b15ae7b
to
672b271
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a good idea, I'll let other folks chime in 😄
672b271
to
f73e8be
Compare
d5dbc6e
to
6b8f1e3
Compare
@davidpfarrell wanna take a look before I merge? |
476fb8b
to
48764d3
Compare
@gaelicWizard so far I like this, but do want to do a deeper review after preexec has been dealt with. As for right now, I'd also like to add "infinite history", but not sure if that belongs in a dedicated plugin. export HISTFILE=$HOME/.bash_history_unlimited
export HISTSIZE=
export HISTFILESIZE= By setting a dedicated file, if the user's environment ever gets reset, their history isn't overwritten and truncated when bash defaults back to |
(No need for |
I'd like to revisit this after we have merged a version of cornfeedhobo#1 |
Man page states HISTFILESIZE=unlimited
HISTSIZE=-1
HISTFILE="${XDG_STATE_HOME:-$HOME/.local/state}/bash_it/history"
Question: what about setting these read-only?
|
As usual, I really appreciate your attention to detail. great job. |
I've read through the linked issue, and I'm kinda stuck on the question of why we are letting themes mess with history at all. I looked through the repo's various |
I agree completely; my goal here is to fix/reduce/remove themes from managing history. |
3e25eda
to
15a79e0
Compare
I've rebased this on the recent cleanup of the history plugins, but I'm going to test it out for a minute to make sure ń̥o҉̙̻̖̲̮͓̩̀t̵̬̳͔ḩ̡̪͇͈i̼̦̮̙͝n̸̸̲̲͍̟g͏̭͖̠̩̭ went funny in the mean time. 😃 |
4f59355
to
ccfda10
Compare
Ok, I've refactored slightly. There's four commits. The first three just do a little cleanup on the existing plugins, and the last one adds the "automatic history management" feature. A few minor notes:
|
c27eb5e
to
8c9406d
Compare
f87395a
to
11f59ea
Compare
d422509
to
221a807
Compare
11dc6ad
to
03c0a80
Compare
At long last, I'm happy to report that this bad boy is ready to go! |
9813705
to
f5d40e5
Compare
...so the plugin is friendly to variables already marked read-only.
...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
There's no need for these plugins to load after `plugin/history`. None of the history plugins depend upon each other loading before, after, or at all.
Two new functions `_bash-it-history-auto-save()` and `_bash-it-history-auto-load()`, which append new history to disk and load new history from disk, respectively. See Bash-it#1595 for discussion.
Description
Two new functions
_bash_it_history_auto_save()
and_bash_it_history_auto_load()
, which append new history to disk and load new history from disk, respectively.These functions operate based on four modes configured in
$HISTCONTROL
:autoshare
: append to$HISTFILE
when_bash_it_history_auto_save()
called, and read from$HISTFILE
when_bash_it_history_auto_load()
called.autosave
: append to$HISTFILE
when_bash_it_history_auto_save()
called, but do not do anything when_bash_it_history_auto_load()
called.autoload
: do not do anything when_bash_it_history_auto_save()
called, but do read from$HISTFILE
when_bash_it_history_auto_load()
called.noauto
(default): don't do anything.Motivation and Context
This PR is based on @davidpfarrell's suggestions in and fixes #1595.
_bash_it_history_auto_save()
should be added topreexec
hook and_bash_it_history_auto_load()
should be added toprecmd
hook, so history is saved immediately and loaded on the next prompt.Ok, I've refactored slightly. There's four commits. The first three just do a little cleanup on the existing plugins, and the last one adds the "automatic history management" feature.
A few minor notes:
export
as it exports the variable to the environment of external binaries, which both adds clutter and alsö can occasionally (ksh
?) cause very unexpected weirds including potential loss of the history file. We don't want a newly executedbash
orksh
to inherit$HISTFILE
but then otherwise set$HISTFILESIZE
to anything shorter.readonly
only survives the current shell, so make sure not toexport
.readonly
inplugin/history-eternal
so that all three variables ($HISTSIZE
,$HISTFILESIZE
, and$HISTFILE
) are all set simultaneously and aren't mis-matched by some clumsy script or plugin somewhere else. This combination ensures that the user's eternal history file is only touched with proper settings configured (or by hand).history -a
) on every run (unless configured not to). This is due to the fact that thepreexec
hook sometimes doesn't run due to weirds relating to emulating using theDEBUG
hook, so just I save history twice. The cases where thepreexec
hook doesn't run are nearly instantaneous, so no functionality is lost. This doesn't have a performance penalty as Bash doesn't actually save twice; it doesn't do anything when asked to append to an up-to-date history file. This combination maximizes the synchronicity of multiple shells writing to the file. Both running shells should see and update the file immediately, before and after user input.I don't think that history management should be handled by the theme. We can set some defaults in
plugins/history
and let the user customize further. Maybe add to the template?How Has This Been Tested?
Tested locally, and all tests pass.
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.