diff --git a/config/preset/theme.toml b/config/preset/theme.toml index b2a25c77..d73c0327 100644 --- a/config/preset/theme.toml +++ b/config/preset/theme.toml @@ -54,14 +54,17 @@ rules = [ [icons] -"Desktop/" = "" -"Documents/" = "" -"Downloads/" = "" -"Music/" = "" -"Pictures/" = "" -"Public/" = "" -"Videos/" = "" -".config/" = "" +"Desktop/" = "" +"Documents/" = "" +"Downloads/" = "" +"Pictures/" = "" +"Music/" = "" +"Movies/" = "" +"Videos/" = "" +"Public/" = "" +"Library/" = "" +"Development/" = "" +".config/" = "" # Git ".git/" = "" diff --git a/config/src/pattern.rs b/config/src/pattern.rs index b2875ba3..1b5bdc60 100644 --- a/config/src/pattern.rs +++ b/config/src/pattern.rs @@ -7,13 +7,22 @@ use serde::Deserialize; pub struct Pattern { inner: glob::Pattern, is_folder: bool, + full_path: bool, } impl Pattern { + #[inline] pub fn matches(&self, str: impl AsRef) -> bool { self.inner.matches(str.as_ref()) } + #[inline] pub fn match_path(&self, path: impl AsRef, is_folder: Option) -> bool { - is_folder.map_or(true, |f| f == self.is_folder) && self.inner.matches_path(path.as_ref()) + let path = path.as_ref(); + let s = if self.full_path { + path.to_str() + } else { + path.file_name().and_then(|n| n.to_str()).or(path.to_str()) + }; + is_folder.map_or(true, |f| f == self.is_folder) && s.map_or(false, |s| self.matches(s)) } } @@ -21,8 +30,12 @@ impl TryFrom<&str> for Pattern { type Error = anyhow::Error; fn try_from(s: &str) -> Result { - let is_folder = s.ends_with('/'); - Ok(Self { inner: glob::Pattern::new(s.trim_end_matches('/'))?, is_folder }) + let new = s.trim_end_matches('/'); + Ok(Self { + inner: glob::Pattern::new(new)?, + is_folder: new.len() < s.len(), + full_path: new.contains('/'), + }) } }