Comment by apodik
2 days ago
is there a particular reason why i'd want sqlite-backed shell history? i mean sure it works but why not a text file? (which i'd assume is somewhat faster because you can just append)
i guess you could say it's because you may want dates for each command but for that you can just use a CSV or TSV file no?
does it have to do with the searching?
In my case, I use Atuin. It has a concept of "context" so you can easily search the history for commands related to your current directory / project / etc. See [0] for some examples.
Now, I admit I don't use these that often, but they can be useful.
It also does stats and whatnot based on the history. I've never looked at those.
[0] https://docs.atuin.sh/latest/guide/advanced-usage/
I have a regular Bash shell history with about 750 000 entries on an SSD on a modern laptop, and would take about 1 second for Bash to load 1 million entries. The startup delay and the memory usage is noticeable.
Storing the shell command history in a database instead of the memory of each interactive Bash shell, it would make Bash start up faster, and also use less memory.
SQLite gives indexes that makes searching and locating previous entries much faster. This is relevant when the history is over 100K entries and one wants to avoid duplicates in history files.
I think you're underestimating the speed of modern computers and hard-drives, fzf can search through 100k entries easily without any delay. Try it with `cat /usr/share/dict/words | fzf`, it's extremely responsive (my dictionary is about 235k lines). If you want hard numbers, try piping your shell history through `time grep` and see how long finding an entry takes.
Even if you're on spinning rust, your shell history is probably in cache. You don't really need FST index for this usecase, IMHO.
With SQLite one automatically gets reliable persistent storage. Try to emulate that with a text file with history that eliminates duplicates. It is surprisingly hard to archive.
I use SQLite history to have context aware line suggestion in my shell. So the command that gets ghost displayed (and can be expanded with right arrow) depends on the current working directory, its parents and recency. This is fast enough using SQLite to just dump all commands into it and query on each typed letter.
The DB is at this point 10years old. I use it to evaluate my work habits and patterns. More recently I have started transitioning to a different shell and I used it to move only the functions and aliases I still use, instead of the full collection.