diff options
Diffstat (limited to 'src/project.rs')
-rw-r--r-- | src/project.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/project.rs b/src/project.rs index d05da37..a35c17e 100644 --- a/src/project.rs +++ b/src/project.rs @@ -15,13 +15,15 @@ use crate::{parser::FilterMap, path::PathMatcher, tmux::Tmux}; pub struct Projects { inner: HashMap<PathBuf, Duration>, filters: Vec<Box<dyn FilterMap>>, + excludes: Vec<PathBuf>, mtime: bool, } impl Projects { - pub fn new(fallback: bool) -> Self { + pub fn new(mtime: bool, excludes: Vec<PathBuf>) -> Self { Self { - mtime: fallback, + mtime, + excludes, ..Default::default() } } @@ -34,6 +36,10 @@ impl Projects { let span = tracing::trace_span!("Entry", ?item); let _guard = span.enter(); + if self.excludes.iter().any(|p| &item.path_buf == p) { + return; + } + match self.inner.entry(item.path_buf) { Entry::Occupied(mut occupied) if &item.timestamp > occupied.get() => { trace!(?occupied, new_value=?item.timestamp, "New entry is more recent, replacing"); @@ -105,22 +111,27 @@ impl Extend<Project> for Projects { impl From<crate::config::Projects> for Projects { fn from(value: crate::config::Projects) -> Self { - let mut projects = Projects::new(value.mtime); + let mut filters: Vec<Box<dyn FilterMap>> = Vec::new(); if let Some(pattern) = &value.pattern { - projects.add_filter(PathMatcher(pattern.to_owned())); + filters.push(Box::new(PathMatcher(pattern.to_owned()))); } if value.tmux { - projects.add_filter(Tmux); + filters.push(Box::new(Tmux)); } #[cfg(feature = "git")] if value.git { - projects.add_filter(crate::git::Git); + filters.push(Box::new(crate::git::Git)); } - projects + Self { + filters, + excludes: value.excludes, + mtime: value.mtime, + ..Default::default() + } } } @@ -146,9 +157,9 @@ impl From<(PathBuf, Duration)> for Project { } impl From<(&PathBuf, &Duration)> for Project { - fn from((path_buf, timestamp): (&PathBuf, &Duration)) -> Self { + fn from((path_buf, ×tamp): (&PathBuf, &Duration)) -> Self { Self { - timestamp: *timestamp, + timestamp, path_buf: path_buf.to_owned(), } } |