aboutsummaryrefslogtreecommitdiffstats
path: root/src/local
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-02-13 22:06:27 +0000
committerEllie Huxtable <e@elm.sh>2021-02-13 22:06:27 +0000
commitd8aacb4a806c097fb316305dab8c481546d72b8b (patch)
treee30757902c93c3ccd8f99d14fb6360545566ee6b /src/local
parentUpdate readme (diff)
downloadatuin-d8aacb4a806c097fb316305dab8c481546d72b8b.zip
Add fuzzy history search and distinct arg
Diffstat (limited to 'src/local')
-rw-r--r--src/local/database.rs34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/local/database.rs b/src/local/database.rs
index e9882fd7..2b014bc0 100644
--- a/src/local/database.rs
+++ b/src/local/database.rs
@@ -11,7 +11,7 @@ pub trait Database {
fn save(&mut self, h: History) -> Result<()>;
fn save_bulk(&mut self, h: &Vec<History>) -> Result<()>;
fn load(&self, id: &str) -> Result<History>;
- fn list(&self) -> Result<()>;
+ fn list(&self, distinct: bool) -> Result<()>;
fn update(&self, h: History) -> Result<()>;
}
@@ -149,33 +149,29 @@ impl Database for SqliteDatabase {
Ok(())
}
- fn list(&self) -> Result<()> {
+ fn list(&self, distinct: bool) -> Result<()> {
debug!("listing history");
- let mut stmt = self.conn.prepare(
- "SELECT id, timestamp, duration, exit, command, cwd, session, hostname FROM history",
- )?;
+ let mut stmt = match distinct {
+ false => self
+ .conn
+ .prepare("SELECT command FROM history order by timestamp asc")?,
+
+ true => self
+ .conn
+ .prepare("SELECT distinct command FROM history order by timestamp asc")?,
+ };
let history_iter = stmt.query_map(params![], |row| {
- Ok(History {
- id: row.get(0)?,
- timestamp: row.get(1)?,
- duration: row.get(2)?,
- exit: row.get(3)?,
- command: row.get(4)?,
- cwd: row.get(5)?,
- session: row.get(6)?,
- hostname: row.get(7)?,
- })
+ let command: String = row.get(0)?;
+
+ Ok(command)
})?;
for h in history_iter {
let h = h.unwrap();
- println!(
- "{} | {} | {} | {} | {} | {} | {}",
- h.timestamp, h.hostname, h.session, h.cwd, h.duration, h.exit, h.command
- );
+ println!("{}", h);
}
Ok(())