feat(script): Add %pid% token for tail commands

Is replaced with the pid of the exec command
This commit is contained in:
patrick96 2018-01-02 13:52:34 +01:00 committed by NBonaparte
parent 1739e4490d
commit f79aeac872
2 changed files with 26 additions and 3 deletions

View File

@ -29,6 +29,8 @@ namespace modules {
unique_ptr<command> m_command;
bool m_tail;
string m_exec;
string m_exec_if;

View File

@ -13,9 +13,11 @@ namespace modules {
*/
script_module::script_module(const bar_settings& bar, string name_)
: module<script_module>(bar, move(name_)), m_handler([&]() -> function<chrono::duration<double>()> {
m_tail = m_conf.get(name(), "tail", false);
// Handler for continuous tail commands {{{
if (m_conf.get(name(), "tail", false)) {
if (m_tail) {
return [&] {
if (!m_command || !m_command->is_running()) {
string exec{string_util::replace_all(m_exec, "%counter%", to_string(++m_counter))};
@ -174,19 +176,38 @@ namespace modules {
if (!m_actions[mousebtn::LEFT].empty()) {
m_builder->cmd(mousebtn::LEFT, string_util::replace_all(m_actions[mousebtn::LEFT], "%counter%", cnt));
if(m_tail && m_command && m_command->is_running()) {
m_builder->cmd(mousebtn::LEFT, string_util::replace_all(m_actions[mousebtn::LEFT], "%pid%", std::to_string(m_command->get_pid())));
}
}
if (!m_actions[mousebtn::MIDDLE].empty()) {
m_builder->cmd(mousebtn::MIDDLE, string_util::replace_all(m_actions[mousebtn::MIDDLE], "%counter%", cnt));
if(m_tail && m_command && m_command->is_running()) {
m_builder->cmd(mousebtn::MIDDLE, string_util::replace_all(m_actions[mousebtn::MIDDLE], "%pid%", std::to_string(m_command->get_pid())));
}
}
if (!m_actions[mousebtn::RIGHT].empty()) {
m_builder->cmd(mousebtn::RIGHT, string_util::replace_all(m_actions[mousebtn::RIGHT], "%counter%", cnt));
if(m_tail && m_command && m_command->is_running()) {
m_builder->cmd(mousebtn::RIGHT, string_util::replace_all(m_actions[mousebtn::RIGHT], "%pid%", std::to_string(m_command->get_pid())));
}
}
if (!m_actions[mousebtn::SCROLL_UP].empty()) {
m_builder->cmd(mousebtn::SCROLL_UP, string_util::replace_all(m_actions[mousebtn::SCROLL_UP], "%counter%", cnt));
if(m_tail && m_command && m_command->is_running()) {
m_builder->cmd(mousebtn::SCROLL_UP, string_util::replace_all(m_actions[mousebtn::SCROLL_UP], "%pid%", std::to_string(m_command->get_pid())));
}
}
if (!m_actions[mousebtn::SCROLL_DOWN].empty()) {
m_builder->cmd(
mousebtn::SCROLL_DOWN, string_util::replace_all(m_actions[mousebtn::SCROLL_DOWN], "%counter%", cnt));
m_builder->cmd( mousebtn::SCROLL_DOWN, string_util::replace_all(m_actions[mousebtn::SCROLL_DOWN], "%counter%", cnt));
if(m_tail && m_command && m_command->is_running()) {
m_builder->cmd(mousebtn::SCROLL_DOWN, string_util::replace_all(m_actions[mousebtn::SCROLL_DOWN], "%pid%", std::to_string(m_command->get_pid())));
}
}
m_builder->append(output);