diff options
author | Tim Ledbetter <timledbetter@gmail.com> | 2023-05-30 17:51:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-31 06:04:48 +0200 |
commit | f5da6d61b43e38b02c22b35f074966c1a36cd797 (patch) | |
tree | cd2047bdd54243ba625c9e205eb2dd588644e143 /Userland | |
parent | 821bf5e071f3d9b44fffa7c632d24830e3833ff2 (diff) | |
download | serenity-f5da6d61b43e38b02c22b35f074966c1a36cd797.zip |
pgrep: Add `-x` option to only select exact matches
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Utilities/pgrep.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Utilities/pgrep.cpp b/Userland/Utilities/pgrep.cpp index ce0ca0698a..9bf0212ab4 100644 --- a/Userland/Utilities/pgrep.cpp +++ b/Userland/Utilities/pgrep.cpp @@ -27,6 +27,7 @@ ErrorOr<int> serenity_main(Main::Arguments args) bool case_insensitive = false; bool list_process_name = false; bool invert_match = false; + bool exact_match = false; HashTable<uid_t> uids_to_filter_by; StringView pattern; @@ -60,6 +61,7 @@ ErrorOr<int> serenity_main(Main::Arguments args) }, }); args_parser.add_option(invert_match, "Select non-matching lines", "invert-match", 'v'); + 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); @@ -67,6 +69,12 @@ ErrorOr<int> serenity_main(Main::Arguments args) if (case_insensitive) options |= PosixFlags::Insensitive; + StringBuilder exact_pattern_builder; + if (exact_match) { + exact_pattern_builder.appendff("^({})$", pattern); + pattern = exact_pattern_builder.string_view(); + } + Regex<PosixExtended> re(pattern, options); if (re.parser_result.error != regex::Error::NoError) { return 1; |