mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
pgrep: Add -d option to specify a pid delimiter
This is useful for commands which expect a comma-separated list of pids.
This commit is contained in:
parent
e30dcc7391
commit
5a9a27cea0
Notes:
sideshowbarker
2024-07-17 02:28:18 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/5a9a27cea0 Pull-request: https://github.com/SerenityOS/serenity/pull/18857 Reviewed-by: https://github.com/caoimhebyrne ✅
@ -19,11 +19,13 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||||||
TRY(Core::System::unveil("/etc/passwd", "r"));
|
TRY(Core::System::unveil("/etc/passwd", "r"));
|
||||||
TRY(Core::System::unveil(nullptr, nullptr));
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
|
|
||||||
|
auto pid_delimiter = "\n"sv;
|
||||||
bool case_insensitive = false;
|
bool case_insensitive = false;
|
||||||
bool invert_match = false;
|
bool invert_match = false;
|
||||||
StringView pattern;
|
StringView pattern;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
|
args_parser.add_option(pid_delimiter, "Set the string used to delimit multiple pids", "delimiter", 'd', nullptr);
|
||||||
args_parser.add_option(case_insensitive, "Make matches case-insensitive", nullptr, 'i');
|
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(invert_match, "Select non-matching lines", "invert-match", 'v');
|
||||||
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");
|
||||||
@ -50,9 +52,18 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||||||
|
|
||||||
quick_sort(matches);
|
quick_sort(matches);
|
||||||
|
|
||||||
|
auto displayed_at_least_one = false;
|
||||||
for (auto& match : matches) {
|
for (auto& match : matches) {
|
||||||
outln("{}", match);
|
if (displayed_at_least_one)
|
||||||
|
out("{}{}"sv, pid_delimiter, match);
|
||||||
|
else
|
||||||
|
out("{}"sv, match);
|
||||||
|
|
||||||
|
displayed_at_least_one = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (displayed_at_least_one)
|
||||||
|
outln();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user