Skip to content

Commit 65f3cba

Browse files
committed
Add option: zoxide query -t : print last_accessed
Closes #1037 rustc 1.88.0-nightly (934880f58 2025-04-09)
1 parent 7691d7e commit 65f3cba

File tree

9 files changed

+28
-4
lines changed

9 files changed

+28
-4
lines changed

contrib/completions/_zoxide

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/_zoxide.ps1

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zoxide.bash

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zoxide.elv

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zoxide.fish

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zoxide.ts

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/cmd.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub struct Add {
5959
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
6060
pub paths: Vec<PathBuf>,
6161

62-
/// The rank to increment the entry if it exists or initialize it with if it doesn't
62+
/// The rank to increment the entry if it exists or initialize it with if it
63+
/// doesn't
6364
#[clap(short, long)]
6465
pub score: Option<f64>,
6566
}
@@ -181,6 +182,10 @@ pub struct Query {
181182
#[clap(long, short)]
182183
pub score: bool,
183184

185+
/// Print last_accessed with results
186+
#[clap(long, short)]
187+
pub time: bool,
188+
184189
/// Exclude the current directory
185190
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
186191
pub exclude: Option<String>,

src/cmd/query.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ impl Query {
5858
if Some(dir.path.as_ref()) == self.exclude.as_deref() {
5959
continue;
6060
}
61-
let dir = if self.score { dir.display().with_score(now) } else { dir.display() };
61+
let mut dir = if self.score { dir.display().with_score(now) } else { dir.display() };
62+
if self.time {
63+
dir.show_last_accessed = true;
64+
}
6265
writeln!(handle, "{dir}").pipe_exit("stdout")?;
6366
}
6467
Ok(())

src/db/dir.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ pub struct DirDisplay<'a> {
3737
dir: &'a Dir<'a>,
3838
now: Option<Epoch>,
3939
separator: char,
40+
pub show_last_accessed: bool,
4041
}
4142

4243
impl<'a> DirDisplay<'a> {
4344
fn new(dir: &'a Dir) -> Self {
44-
Self { dir, separator: ' ', now: None }
45+
Self { dir, separator: ' ', now: None, show_last_accessed: false }
4546
}
4647

4748
pub fn with_score(mut self, now: Epoch) -> Self {
@@ -61,6 +62,10 @@ impl Display for DirDisplay<'_> {
6162
let score = self.dir.score(now).clamp(0.0, 9999.0);
6263
write!(f, "{score:>6.1}{}", self.separator)?;
6364
}
65+
if self.show_last_accessed {
66+
let last_accessed = self.dir.last_accessed;
67+
write!(f, "{last_accessed:>6.1}{}", self.separator)?;
68+
}
6469
write!(f, "{}", self.dir.path)
6570
}
6671
}

0 commit comments

Comments
 (0)