aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/history.rs7
-rw-r--r--src/local/database.rs34
2 files changed, 20 insertions, 21 deletions
diff --git a/src/command/history.rs b/src/command/history.rs
index 4caf4c17..f8a5b27e 100644
--- a/src/command/history.rs
+++ b/src/command/history.rs
@@ -28,7 +28,10 @@ pub enum HistoryCmd {
about="list all items in history",
aliases=&["l", "li", "lis"],
)]
- List,
+ List {
+ #[structopt(long)]
+ distinct: bool,
+ },
}
impl HistoryCmd {
@@ -65,7 +68,7 @@ impl HistoryCmd {
Ok(())
}
- HistoryCmd::List => db.list(),
+ HistoryCmd::List { distinct } => db.list(*distinct),
}
}
}
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(())