mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
fix: no matches of some icons (#19)
This commit is contained in:
parent
5b88c68236
commit
78ee5e9ac8
2 changed files with 27 additions and 11 deletions
|
|
@ -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/" = ""
|
||||
|
|
|
|||
|
|
@ -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<str>) -> bool { self.inner.matches(str.as_ref()) }
|
||||
|
||||
#[inline]
|
||||
pub fn match_path(&self, path: impl AsRef<Path>, is_folder: Option<bool>) -> 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<Self, Self::Error> {
|
||||
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('/'),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue