From a8cba9c43c2633aa716af06ebe720c5d6948a63a Mon Sep 17 00:00:00 2001 From: patrick96 Date: Mon, 13 Sep 2021 14:06:08 +0200 Subject: [PATCH] fix(ipc): Replace all %pid% tokens Fixes #2500 --- CHANGELOG.md | 2 ++ src/modules/ipc.cpp | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 380dc37e..f37ceb0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The tray mistakenly removed tray icons that did not support XEMBED ([`#2479`](https://github.com/polybar/polybar/issues/2479), [`#2442`](https://github.com/polybar/polybar/issues/2442)) +- `custom/ipc`: Only the first appearance of the `%pid%` token was replaced + ([`#2500`](https://github.com/polybar/polybar/issues/2500)) ## [3.5.6] - 2021-05-24 ### Build diff --git a/src/modules/ipc.cpp b/src/modules/ipc.cpp index c8082769..d95ab8dc 100644 --- a/src/modules/ipc.cpp +++ b/src/modules/ipc.cpp @@ -38,18 +38,15 @@ namespace modules { m_actions.emplace(make_pair(mousebtn::DOUBLE_RIGHT, m_conf.get(name(), "double-click-right", ""s))); // clang-format on - const auto pid_token = [](string& s) { - string::size_type p = s.find("%pid%"); - if (p != string::npos) { - s.replace(p, 5, to_string(getpid())); - } + const auto pid_token = [](const string& s) { + return string_util::replace_all(s, "%pid%", to_string(getpid())); }; for (auto& action : m_actions) { - pid_token(action.second); + action.second = pid_token(action.second); } for (auto& hook : m_hooks) { - pid_token(hook->command); + hook->command = pid_token(hook->command); } m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});