From 647f89f15ee39355241795a9b8bd116a82fbec91 Mon Sep 17 00:00:00 2001 From: Marco Cutecchia Date: Sat, 30 Oct 2021 12:54:26 +0200 Subject: [PATCH] Utilities: Add 'quiet' mode to grep --- Userland/Utilities/grep.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Userland/Utilities/grep.cpp b/Userland/Utilities/grep.cpp index 5e352053a59..6bb2f7abc9f 100644 --- a/Userland/Utilities/grep.cpp +++ b/Userland/Utilities/grep.cpp @@ -47,6 +47,7 @@ int main(int argc, char** argv) BinaryFileMode binary_mode { BinaryFileMode::Binary }; bool case_insensitive = false; bool invert_match = false; + bool quiet_mode = false; bool colored_output = isatty(STDOUT_FILENO); Core::ArgsParser args_parser; @@ -55,6 +56,7 @@ int main(int argc, char** argv) args_parser.add_option(pattern, "Pattern", "regexp", 'e', "Pattern"); args_parser.add_option(case_insensitive, "Make matches case-insensitive", nullptr, 'i'); args_parser.add_option(invert_match, "Select non-matching lines", "invert-match", 'v'); + args_parser.add_option(quiet_mode, "Do not write anything to standard output", "quiet", 'q'); args_parser.add_option(Core::ArgsParser::Option { .requires_argument = true, .help_string = "Action to take for binary files ([binary], text, skip)", @@ -132,6 +134,9 @@ int main(int argc, char** argv) auto result = re.match(str, PosixFlags::Global); if (result.success ^ invert_match) { + if (quiet_mode) + return true; + if (is_binary && binary_mode == BinaryFileMode::Binary) { outln(colored_output ? "binary file \x1B[34m{}\x1B[0m matches" : "binary file {} matches", filename); } else {