aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorEllie Huxtable <e@elm.sh>2021-02-13 17:02:52 +0000
committerEllie Huxtable <e@elm.sh>2021-02-13 17:02:52 +0000
commit7e60ace610ea3d137fac8fd6cfb26a1f5411a609 (patch)
tree493142aa562fa379f82e4f6b2e2a79fa7f9b085b /src/main.rs
parentBegin import (diff)
downloadatuin-7e60ace610ea3d137fac8fd6cfb26a1f5411a609.zip
Record command exit code and duration
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 30 insertions, 8 deletions
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<String> },
+ Start { command: Vec<String> },
+
+ #[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(())
}