summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorTim Ledbetter <timledbetter@gmail.com>2023-05-15 17:35:02 +0100
committerAndreas Kling <kling@serenityos.org>2023-05-16 12:49:15 +0200
commit5a9a27cea0aefcb90d0eb73d275d7cec13c2e7d1 (patch)
tree5dde27d8f6dbd55439e3a1418cd55d9782f2580f /Userland/Utilities
parente30dcc7391a53aa5cba7a277e0e67df42cca0441 (diff)
downloadserenity-5a9a27cea0aefcb90d0eb73d275d7cec13c2e7d1.zip
pgrep: Add -d option to specify a pid delimiter
This is useful for commands which expect a comma-separated list of pids.
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/pgrep.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/Userland/Utilities/pgrep.cpp b/Userland/Utilities/pgrep.cpp
index 1b442d2875..2614ef977d 100644
--- a/Userland/Utilities/pgrep.cpp
+++ b/Userland/Utilities/pgrep.cpp
@@ -19,11 +19,13 @@ ErrorOr<int> serenity_main(Main::Arguments args)
TRY(Core::System::unveil("/etc/passwd", "r"));
TRY(Core::System::unveil(nullptr, nullptr));
+ auto pid_delimiter = "\n"sv;
bool case_insensitive = false;
bool invert_match = false;
StringView pattern;
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(invert_match, "Select non-matching lines", "invert-match", 'v');
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);
+ auto displayed_at_least_one = false;
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;
}