Skip to content

Commit

Permalink
Search in command only, not in date/time
Browse files Browse the repository at this point in the history
  • Loading branch information
m42e committed Apr 1, 2022
1 parent da0d385 commit 2e89a0b
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ struct History {
session: i64,
host: String,
dir: String,
searchrange: [(usize, usize);1],
}
impl History {
fn new( id: i64, cmd: String, start: u64, exit_status: Option<i64>, duration: Option<i64>, count: i64, session: i64, host: String, dir: String) -> History{
let myvec = [(11 as usize, cmd.len() + (11 as usize))];
return History{id, cmd, start, exit_status, duration, count, session, host, dir, searchrange:myvec};
}
}

fn get_epoch_start_of_day() -> u64 {
Expand Down Expand Up @@ -65,6 +72,7 @@ impl History {
}

impl SkimItem for History {

fn text(&self) -> Cow<str> {
let information = format!("{:10} {}", self.format_date(false), self.cmd);
Cow::Owned(information)
Expand All @@ -90,6 +98,9 @@ impl SkimItem for History {
));
ItemPreview::AnsiText(information)
}
fn get_matching_ranges(&self) -> Option<&[(usize, usize)]> {
Some(&self.searchrange)
}
}

/// Get the default (which is non us! or the us date format)
Expand Down Expand Up @@ -150,17 +161,17 @@ fn prepare_entries(location: &Location, grouped: bool, tx_item: SkimItemSender)
let mut stmt = stmt_result.unwrap();

let cats = stmt.query_map([], |row| {
Ok(History {
id: row.get(0)?,
cmd: row.get(1)?,
start: row.get(2)?,
exit_status: row.get(3)?,
duration: row.get(4)?,
count: row.get(5)?,
session: row.get(6)?,
host: row.get(7)?,
dir: row.get(8)?,
})
Ok(History::new(
row.get(0)?,
row.get(1)?,
row.get(2)?,
row.get(3)?,
row.get(4)?,
row.get(5)?,
row.get(6)?,
row.get(7)?,
row.get(8)?,
))
});
for person in cats.unwrap() {
if person.is_ok() {
Expand Down

0 comments on commit 2e89a0b

Please sign in to comment.