From c6336cdf3c76b2ba9aa5cb77db3bc9f31b3eb21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 13 Oct 2021 04:06:55 +1300 Subject: [PATCH] Add filetype matcher --- lib/src/filter/tagged.rs | 16 ++++++++++++++++ lib/src/filter/tagged/parse.rs | 2 ++ 2 files changed, 18 insertions(+) diff --git a/lib/src/filter/tagged.rs b/lib/src/filter/tagged.rs index 3003311..1d0c10f 100644 --- a/lib/src/filter/tagged.rs +++ b/lib/src/filter/tagged.rs @@ -203,6 +203,21 @@ impl TaggedFilterer { filter.matches(resolved.to_string_lossy()) } } + ( + Tag::Path { + file_type: Some(ft), + .. + }, + Matcher::FileType, + ) => filter.matches(if ft.is_dir() { + "dir" + } else if ft.is_file() { + "file" + } else if ft.is_symlink() { + "symlink" + } else { + "special" + }), (Tag::FileEventKind(kind), Matcher::FileEventKind) => { filter.matches(format!("{:?}", kind)) } @@ -405,6 +420,7 @@ impl Filter { pub enum Matcher { Tag, Path, + FileType, FileEventKind, Source, Process, diff --git a/lib/src/filter/tagged/parse.rs b/lib/src/filter/tagged/parse.rs index 7b4872a..d6cae5d 100644 --- a/lib/src/filter/tagged/parse.rs +++ b/lib/src/filter/tagged/parse.rs @@ -22,6 +22,7 @@ impl FromStr for Filter { alt(( tag_no_case("tag"), tag_no_case("path"), + tag_no_case("type"), tag_no_case("kind"), tag_no_case("source"), tag_no_case("src"), @@ -32,6 +33,7 @@ impl FromStr for Filter { |m: &str| match m.to_ascii_lowercase().as_str() { "tag" => Ok(Matcher::Tag), "path" => Ok(Matcher::Path), + "type" => Ok(Matcher::FileType), "kind" => Ok(Matcher::FileEventKind), "source" => Ok(Matcher::Source), "src" => Ok(Matcher::Source),