From 69b6c6f62c57a3b6df669f07a047c27e6f7e827d Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sun, 4 Jun 2023 11:40:30 +0100 Subject: [PATCH] pkill: Add `-x` option to only select exact matches --- Userland/Utilities/pkill.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Utilities/pkill.cpp b/Userland/Utilities/pkill.cpp index 96e8cac1645..a908d7b2f52 100644 --- a/Userland/Utilities/pkill.cpp +++ b/Userland/Utilities/pkill.cpp @@ -28,6 +28,7 @@ ErrorOr serenity_main(Main::Arguments args) bool display_number_of_matches; bool case_insensitive = false; bool echo = false; + bool exact_match = false; StringView pattern; HashTable uids_to_filter_by; int signal = SIGTERM; @@ -61,6 +62,7 @@ ErrorOr serenity_main(Main::Arguments args) return true; }, }); + args_parser.add_option(exact_match, "Select only processes whose names match the given pattern exactly", "exact", 'x'); args_parser.add_positional_argument(pattern, "Process name to search for", "process-name"); args_parser.parse(args); @@ -71,6 +73,12 @@ ErrorOr serenity_main(Main::Arguments args) options |= PosixFlags::Insensitive; } + StringBuilder exact_pattern_builder; + if (exact_match) { + exact_pattern_builder.appendff("^({})$", pattern); + pattern = exact_pattern_builder.string_view(); + } + Regex re(pattern, options); if (re.parser_result.error != regex::Error::NoError) { return 1;