From 0f139044b4d76d70a747bb602e91a764c854f46f Mon Sep 17 00:00:00 2001 From: Tom Cammann Date: Tue, 28 Mar 2023 22:06:24 +0100 Subject: [PATCH] Add more fields to `atuin search -f` formatting (#824) - Add `{exit}` which returns the exit code - Add `{relativetime}` which gives a relative time, e.g. "5h" --- src/command/client/history.rs | 7 +++++++ src/command/client/search.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/command/client/history.rs b/src/command/client/history.rs index c8f6b53..76c796e 100644 --- a/src/command/client/history.rs +++ b/src/command/client/history.rs @@ -20,6 +20,7 @@ use atuin_client::{ use atuin_client::sync; use log::debug; +use super::search::format_duration; use super::search::format_duration_into; #[derive(Subcommand)] @@ -115,11 +116,17 @@ impl FormatKey for FmtHistory<'_> { match key { "command" => f.write_str(self.0.command.trim())?, "directory" => f.write_str(self.0.cwd.trim())?, + "exit" => f.write_str(&self.0.exit.to_string())?, "duration" => { let dur = Duration::from_nanos(std::cmp::max(self.0.duration, 0) as u64); format_duration_into(dur, f)?; } "time" => self.0.timestamp.format("%Y-%m-%d %H:%M:%S").fmt(f)?, + "relativetime" => { + let since = chrono::Utc::now() - self.0.timestamp; + let time = format_duration(since.to_std().unwrap_or_default()); + f.write_str(&time)?; + } "host" => f.write_str( self.0 .hostname diff --git a/src/command/client/search.rs b/src/command/client/search.rs index fb3a1a3..7a4d365 100644 --- a/src/command/client/search.rs +++ b/src/command/client/search.rs @@ -79,7 +79,8 @@ pub struct Cmd { #[arg(long)] delete: bool, - /// Available variables: {command}, {directory}, {duration}, {user}, {host} and {time}. + /// Available variables: {command}, {directory}, {duration}, {user}, {host}, {time}, {exit} and + /// {relativetime}. /// Example: --format "{time} - [{duration}] - {directory}$\t{command}" #[arg(long, short)] format: Option,