diff --git a/src/commands.cc b/src/commands.cc index 9d33e85d..98cbdbad 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -861,8 +861,8 @@ const CommandDesc add_hook_cmd = { Regex regex{parser[2], RegexCompileFlags::Optimize}; const String& command = parser[3]; auto group = parser.get_switch("group").value_or(StringView{}); - const auto flags = (parser.get_switch("always") ? HookFlags::Always : HookFlags::None) \ - | (parser.get_switch("once") ? HookFlags::Once : HookFlags::None); + const auto flags = (parser.get_switch("always") ? HookFlags::Always : HookFlags::None) | + (parser.get_switch("once") ? HookFlags::Once : HookFlags::None); get_scope(parser[0], context).hooks().add_hook(parser[1], group.str(), flags, std::move(regex), command); } diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 8dabb66a..3b63ee56 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -126,10 +126,7 @@ void HookManager::run_hook(StringView hook_name, StringView param, Context& cont if (to_run.hook->flags & HookFlags::Once) { - auto it = std::find_if(hook_list->value.begin(), hook_list->value.end(), - [&](const std::unique_ptr& h) - { return h.get() == to_run.hook; }); - + auto it = find(hook_list->value, to_run.hook); m_hooks_trash.push_back(std::move(*it)); hook_list->value.erase(it); } diff --git a/test/hooks/once/cmd b/test/hooks/once/cmd new file mode 100644 index 00000000..b1164fb4 --- /dev/null +++ b/test/hooks/once/cmd @@ -0,0 +1 @@ +iaaa diff --git a/test/hooks/once/in b/test/hooks/once/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/hooks/once/in @@ -0,0 +1 @@ + diff --git a/test/hooks/once/out b/test/hooks/once/out new file mode 100644 index 00000000..d0b67bf0 --- /dev/null +++ b/test/hooks/once/out @@ -0,0 +1 @@ +abaa diff --git a/test/hooks/once/rc b/test/hooks/once/rc new file mode 100644 index 00000000..2a7453bd --- /dev/null +++ b/test/hooks/once/rc @@ -0,0 +1 @@ +hook global -once InsertChar a 'exec b'