Skip to content

Commit 4825eb6

Browse files
Add option: zoxide query -t : print last_accessed
Closes ajeetdsouza#1037 Co-authored-by: Azalea Colburn <[email protected]>
1 parent 9c0dcf1 commit 4825eb6

File tree

9 files changed

+53
-15
lines changed

9 files changed

+53
-15
lines changed

contrib/completions/_zoxide

Lines changed: 9 additions & 7 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: 8 additions & 4 deletions
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: 6 additions & 2 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ pub struct Query {
183183
#[clap(long, short)]
184184
pub score: bool,
185185

186+
/// Print `last_accessed` with results, no effect without `--list` option
187+
#[clap(long, short)]
188+
pub time: bool,
189+
186190
/// Exclude the current directory
187191
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
188192
pub exclude: Option<String>,

src/cmd/query.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ 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 dir = match (self.score, self.time) {
62+
(true, true) => dir.display().with_score(now).with_last_assessed(),
63+
(true, false) => dir.display().with_score(now),
64+
(false, true) => dir.display().with_last_assessed(),
65+
(false, false) => dir.display(),
66+
};
67+
6268
writeln!(handle, "{dir}").pipe_exit("stdout")?;
6369
}
6470
Ok(())

src/db/dir.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,24 @@ pub struct DirDisplay<'a> {
3737
dir: &'a Dir<'a>,
3838
now: Option<Epoch>,
3939
separator: char,
40+
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 {
4849
self.now = Some(now);
4950
self
5051
}
5152

53+
pub fn with_last_assessed(mut self) -> Self {
54+
self.show_last_accessed = true;
55+
self
56+
}
57+
5258
pub fn with_separator(mut self, separator: char) -> Self {
5359
self.separator = separator;
5460
self
@@ -61,6 +67,10 @@ impl Display for DirDisplay<'_> {
6167
let score = self.dir.score(now).clamp(0.0, 9999.0);
6268
write!(f, "{score:>6.1}{}", self.separator)?;
6369
}
70+
if self.show_last_accessed {
71+
let last_accessed = self.dir.last_accessed;
72+
write!(f, "{last_accessed:>6.1}{}", self.separator)?;
73+
}
6474
write!(f, "{}", self.dir.path)
6575
}
6676
}

0 commit comments

Comments
 (0)