1
1
mirror of https://github.com/ellie/atuin.git synced 2024-09-11 21:18:22 +03:00

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"
This commit is contained in:
Tom Cammann 2023-03-28 22:06:24 +01:00 committed by GitHub
parent 3514ff2401
commit 0f139044b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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<String>,