mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
pkill: Add -x
option to only select exact matches
This commit is contained in:
parent
a253be6abf
commit
69b6c6f62c
1 changed files with 8 additions and 0 deletions
|
@ -28,6 +28,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
bool display_number_of_matches;
|
bool display_number_of_matches;
|
||||||
bool case_insensitive = false;
|
bool case_insensitive = false;
|
||||||
bool echo = false;
|
bool echo = false;
|
||||||
|
bool exact_match = false;
|
||||||
StringView pattern;
|
StringView pattern;
|
||||||
HashTable<uid_t> uids_to_filter_by;
|
HashTable<uid_t> uids_to_filter_by;
|
||||||
int signal = SIGTERM;
|
int signal = SIGTERM;
|
||||||
|
@ -61,6 +62,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
return true;
|
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.add_positional_argument(pattern, "Process name to search for", "process-name");
|
||||||
args_parser.parse(args);
|
args_parser.parse(args);
|
||||||
|
|
||||||
|
@ -71,6 +73,12 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
options |= PosixFlags::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);
|
Regex<PosixExtended> re(pattern, options);
|
||||||
if (re.parser_result.error != regex::Error::NoError) {
|
if (re.parser_result.error != regex::Error::NoError) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue