Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contrib/completions/_zoxide

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contrib/completions/_zoxide.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contrib/completions/zoxide.bash

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions contrib/completions/zoxide.elv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contrib/completions/zoxide.fish

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contrib/completions/zoxide.nu

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions contrib/completions/zoxide.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/cmd/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ pub struct Query {
#[clap(long, short)]
pub score: bool,

/// Print `last_accessed` with results, no effect without `--list` option
#[clap(long, short)]
pub time: bool,

/// Exclude the current directory
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
pub exclude: Option<String>,
Expand Down
8 changes: 7 additions & 1 deletion src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ impl Query {
if Some(dir.path.as_ref()) == self.exclude.as_deref() {
continue;
}
let dir = if self.score { dir.display().with_score(now) } else { dir.display() };
let dir = match (self.score, self.time) {
(true, true) => dir.display().with_score(now).with_last_assessed(),
(true, false) => dir.display().with_score(now),
(false, true) => dir.display().with_last_assessed(),
(false, false) => dir.display(),
};

writeln!(handle, "{dir}").pipe_exit("stdout")?;
}
Ok(())
Expand Down
12 changes: 11 additions & 1 deletion src/db/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,24 @@ pub struct DirDisplay<'a> {
dir: &'a Dir<'a>,
now: Option<Epoch>,
separator: char,
show_last_accessed: bool,
}

impl<'a> DirDisplay<'a> {
fn new(dir: &'a Dir) -> Self {
Self { dir, separator: ' ', now: None }
Self { dir, separator: ' ', now: None, show_last_accessed: false }
}

pub fn with_score(mut self, now: Epoch) -> Self {
self.now = Some(now);
self
}

pub fn with_last_assessed(mut self) -> Self {
self.show_last_accessed = true;
self
}

pub fn with_separator(mut self, separator: char) -> Self {
self.separator = separator;
self
Expand All @@ -61,6 +67,10 @@ impl Display for DirDisplay<'_> {
let score = self.dir.score(now).clamp(0.0, 9999.0);
write!(f, "{score:>6.1}{}", self.separator)?;
}
if self.show_last_accessed {
let last_accessed = self.dir.last_accessed;
write!(f, "{last_accessed:>6.1}{}", self.separator)?;
}
write!(f, "{}", self.dir.path)
}
}
Expand Down
Loading