mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41: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]
|
[icons]
|
||||||
|
|
||||||
"Desktop/" = ""
|
"Desktop/" = ""
|
||||||
"Documents/" = ""
|
"Documents/" = ""
|
||||||
"Downloads/" = ""
|
"Downloads/" = ""
|
||||||
"Music/" = ""
|
"Pictures/" = ""
|
||||||
"Pictures/" = ""
|
"Music/" = ""
|
||||||
"Public/" = ""
|
"Movies/" = ""
|
||||||
"Videos/" = ""
|
"Videos/" = ""
|
||||||
".config/" = ""
|
"Public/" = ""
|
||||||
|
"Library/" = ""
|
||||||
|
"Development/" = ""
|
||||||
|
".config/" = ""
|
||||||
|
|
||||||
# Git
|
# Git
|
||||||
".git/" = ""
|
".git/" = ""
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,22 @@ use serde::Deserialize;
|
||||||
pub struct Pattern {
|
pub struct Pattern {
|
||||||
inner: glob::Pattern,
|
inner: glob::Pattern,
|
||||||
is_folder: bool,
|
is_folder: bool,
|
||||||
|
full_path: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pattern {
|
impl Pattern {
|
||||||
|
#[inline]
|
||||||
pub fn matches(&self, str: impl AsRef<str>) -> bool { self.inner.matches(str.as_ref()) }
|
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 {
|
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;
|
type Error = anyhow::Error;
|
||||||
|
|
||||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||||
let is_folder = s.ends_with('/');
|
let new = s.trim_end_matches('/');
|
||||||
Ok(Self { inner: glob::Pattern::new(s.trim_end_matches('/'))?, is_folder })
|
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