mirror of
https://github.com/starship/starship.git
synced 2025-06-27 05:12:15 +02:00
fail the match is any negative files/folders match
This commit is contained in:
parent
f8910f230b
commit
a0ec5bedea
@ -449,27 +449,43 @@ impl DirContents {
|
|||||||
self.file_names.contains(name)
|
self.file_names.contains(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_any_file_name(&self, names: &[&str]) -> bool {
|
|
||||||
names.iter().any(|name| self.has_file_name(name))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_folder(&self, path: &str) -> bool {
|
pub fn has_folder(&self, path: &str) -> bool {
|
||||||
self.folders.contains(Path::new(path))
|
self.folders.contains(Path::new(path))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_any_folder(&self, paths: &[&str]) -> bool {
|
|
||||||
paths.iter().any(|path| self.has_folder(path))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_extension(&self, ext: &str) -> bool {
|
pub fn has_extension(&self, ext: &str) -> bool {
|
||||||
self.extensions.contains(ext)
|
self.extensions.contains(ext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_any_positive_file_name(&self, names: &[&str]) -> bool {
|
||||||
|
names
|
||||||
|
.iter()
|
||||||
|
.any(|name| !name.starts_with('!') && self.has_file_name(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_any_positive_folder(&self, paths: &[&str]) -> bool {
|
||||||
|
paths
|
||||||
|
.iter()
|
||||||
|
.any(|path| !path.starts_with('!') && self.has_folder(path))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_any_positive_extension(&self, exts: &[&str]) -> bool {
|
pub fn has_any_positive_extension(&self, exts: &[&str]) -> bool {
|
||||||
exts.iter()
|
exts.iter()
|
||||||
.any(|ext| !ext.starts_with('!') && self.has_extension(ext))
|
.any(|ext| !ext.starts_with('!') && self.has_extension(ext))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_no_negative_file_name(&self, names: &[&str]) -> bool {
|
||||||
|
!names
|
||||||
|
.iter()
|
||||||
|
.any(|name| name.starts_with('!') && self.has_file_name(&name[1..]))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_no_negative_folder(&self, paths: &[&str]) -> bool {
|
||||||
|
!paths
|
||||||
|
.iter()
|
||||||
|
.any(|path| path.starts_with('!') && self.has_folder(&path[1..]))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn has_no_negative_extension(&self, exts: &[&str]) -> bool {
|
pub fn has_no_negative_extension(&self, exts: &[&str]) -> bool {
|
||||||
!exts
|
!exts
|
||||||
.iter()
|
.iter()
|
||||||
@ -540,14 +556,16 @@ impl<'a> ScanDir<'a> {
|
|||||||
/// based on the current `PathBuf` check to see
|
/// based on the current `PathBuf` check to see
|
||||||
/// if any of this criteria match or exist and returning a boolean
|
/// if any of this criteria match or exist and returning a boolean
|
||||||
pub fn is_match(&self) -> bool {
|
pub fn is_match(&self) -> bool {
|
||||||
// if there exists a file with an extension we've said we don't want,
|
// if there exists a file with a file/folder/ext we've said we don't want,
|
||||||
// fail the match straight away
|
// fail the match straight away
|
||||||
self.dir_contents.has_no_negative_extension(self.extensions)
|
self.dir_contents.has_no_negative_extension(self.extensions)
|
||||||
|
&& self.dir_contents.has_no_negative_file_name(self.files)
|
||||||
|
&& self.dir_contents.has_no_negative_folder(self.folders)
|
||||||
&& (self
|
&& (self
|
||||||
.dir_contents
|
.dir_contents
|
||||||
.has_any_positive_extension(self.extensions)
|
.has_any_positive_extension(self.extensions)
|
||||||
|| self.dir_contents.has_any_folder(self.folders)
|
|| self.dir_contents.has_any_positive_file_name(self.files)
|
||||||
|| self.dir_contents.has_any_file_name(self.files))
|
|| self.dir_contents.has_any_positive_folder(self.folders))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user