pub struct HistoryEngine { /* private fields */ }Expand description
SQLite-backed history engine.
Replaces the in-memory histent doubly-linked list +
histfile flat-file pair from Src/hist.c — same logical
history but with FTS5 search, frequency tracking, and
per-directory context.
Implementations§
Source§impl HistoryEngine
impl HistoryEngine
Sourcepub fn db_path() -> PathBuf
pub fn db_path() -> PathBuf
$ZSHRS_HOME/zshrs_history.db — sqlite index that powers FTS5
search, frequency tracking, dedup. Hidden under .db so the
user-facing artifact is the flat-text mirror at
zshrs_history (see text_path), zsh-compatible so muscle
memory + cat / grep / external history tools all keep
working.
The daemon owns its OWN history db at ~/.zshrs/history.db
(different schema, daemon-only writer); shells append to it via
history_append IPC. This shell-side db is the fallback path
used when the daemon is absent.
Sourcepub fn text_path() -> PathBuf
pub fn text_path() -> PathBuf
$ZSHRS_HOME/zshrs_history — flat text mirror, one line per
command in zsh extended-history format:
: <unix_ts>:<duration>;<command>A newline inside a multi-line command is written as a backslash
followed by the newline, so one record can span several physical
lines (zsh/Src/hist.c:savehistfile). Each record is appended
once, by update_last, when the command has finished and its
duration is known; the file is never rewritten in place, so
concurrent shells cannot clobber each other’s records. The sqlite
index at zshrs_history.db is the query side; a missing or empty
text file is rehydrated from it on open.
Sourcepub fn add(&self, command: &str, cwd: Option<&str>) -> Result<i64>
pub fn add(&self, command: &str, cwd: Option<&str>) -> Result<i64>
Add a command to history, updating frequency if it already exists
Sourcepub fn update_last(
&self,
id: i64,
duration_ms: i64,
exit_code: i32,
) -> Result<()>
pub fn update_last( &self, id: i64, duration_ms: i64, exit_code: i32, ) -> Result<()>
Update the duration and exit code of the last command
Sourcepub fn search(&self, query: &str, limit: usize) -> Result<Vec<HistoryEntry>>
pub fn search(&self, query: &str, limit: usize) -> Result<Vec<HistoryEntry>>
Search history with FTS5 (fuzzy/substring matching)
Sourcepub fn search_prefix(
&self,
prefix: &str,
limit: usize,
) -> Result<Vec<HistoryEntry>>
pub fn search_prefix( &self, prefix: &str, limit: usize, ) -> Result<Vec<HistoryEntry>>
Search history with prefix matching (for up-arrow completion)
Sourcepub fn search_prefix_cs(
&self,
prefix: &str,
limit: usize,
) -> Result<Vec<HistoryEntry>>
pub fn search_prefix_cs( &self, prefix: &str, limit: usize, ) -> Result<Vec<HistoryEntry>>
Case-SENSITIVE prefix probe for the per-keystroke ZLE paths
(autosuggest, up-arrow search). Uses GLOB, which is case-sensitive and
therefore eligible for the SQLite prefix optimization over
idx_history_command (BINARY collation). search_prefix’s LIKE is
case-insensitive by default and CANNOT use that index — at 500k+ rows
it full-scans, which is far too slow to run on every keystroke.
Sourcepub fn for_directory(
&self,
cwd: &str,
limit: usize,
) -> Result<Vec<HistoryEntry>>
pub fn for_directory( &self, cwd: &str, limit: usize, ) -> Result<Vec<HistoryEntry>>
Get history for a specific directory
Sourcepub fn count_estimate(&self) -> Result<i64>
pub fn count_estimate(&self) -> Result<i64>
Row-count ESTIMATE that does not scan the table.
MAX(rowid) is resolved by descending to the rightmost leaf of the
rowid b-tree, so it is independent of table size where COUNT(*) is
linear in it (37 ms at 775k rows). It equals the true count for an
append-only history and over-reports by the number of deleted rows
otherwise — good enough for a log line, never used for arithmetic on
history events.
Sourcepub fn get_by_offset(&self, offset: usize) -> Result<Option<HistoryEntry>>
pub fn get_by_offset(&self, offset: usize) -> Result<Option<HistoryEntry>>
Get entry by index from end (0 = most recent, like !-1)
Sourcepub fn get_by_number(&self, num: i64) -> Result<Option<HistoryEntry>>
pub fn get_by_number(&self, num: i64) -> Result<Option<HistoryEntry>>
Get entry by absolute history number (like !123)
Auto Trait Implementations§
impl !Freeze for HistoryEngine
impl !RefUnwindSafe for HistoryEngine
impl !Sync for HistoryEngine
impl !UnwindSafe for HistoryEngine
impl Send for HistoryEngine
impl Unpin for HistoryEngine
impl UnsafeUnpin for HistoryEngine
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more