From 7e60ace610ea3d137fac8fd6cfb26a1f5411a609 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Sat, 13 Feb 2021 17:02:52 +0000 Subject: Record command exit code and duration --- src/main.rs | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index a9b4b8af..57688a4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,10 +74,20 @@ impl Atuin { #[derive(StructOpt)] enum HistoryCmd { #[structopt( - about="add a new command to the history", - aliases=&["a", "ad"], + about="begins a new command in the history", + aliases=&["s", "st", "sta", "star"], )] - Add { command: Vec }, + Start { command: Vec }, + + #[structopt( + about="finishes a new command in the history (adds time, exit code)", + aliases=&["e", "en"], + )] + End { + id: String, + #[structopt(long, short)] + exit: i64, + }, #[structopt( about="list all items in history", @@ -87,16 +97,28 @@ enum HistoryCmd { } impl HistoryCmd { - fn run(self, db: SqliteDatabase) -> Result<()> { + fn run(&self, db: SqliteDatabase) -> Result<()> { match self { - HistoryCmd::Add { command: words } => { + HistoryCmd::Start { command: words } => { let command = words.join(" "); let cwd = env::current_dir()?.display().to_string(); - let h = History::new(command, cwd); - debug!("adding history: {:?}", h); + let h = History::new(command, cwd, -1, -1); + + // print the ID + // we use this as the key for calling end + println!("{}", h.id); db.save(h)?; - debug!("saved history to sqlite"); + Ok(()) + } + + HistoryCmd::End { id, exit } => { + let mut h = db.load(id)?; + h.exit = *exit; + h.duration = chrono::Utc::now().timestamp_millis() - h.timestamp; + + db.update(h)?; + Ok(()) } -- cgit v1.3.1