From cc743dc296f9f8b5505ee217f15748f8d7c2b343 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 4 Jul 2018 12:30:52 +0000 Subject: Add set-hook -R to run a hook immediately (useful to set multiple hooks to the same thing). --- cmd-set-hook.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'cmd-set-hook.c') diff --git a/cmd-set-hook.c b/cmd-set-hook.c index d0cd98db..b04e6335 100644 --- a/cmd-set-hook.c +++ b/cmd-set-hook.c @@ -33,8 +33,8 @@ const struct cmd_entry cmd_set_hook_entry = { .name = "set-hook", .alias = NULL, - .args = { "gt:u", 1, 2 }, - .usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]", + .args = { "gRt:u", 1, 2 }, + .usage = "[-gRu] " CMD_TARGET_SESSION_USAGE " hook-name [command]", .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, @@ -101,18 +101,21 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item) else cmd = args->argv[1]; + if (cmd != NULL && (args_has(args, 'R') || args_has(args, 'u'))) { + cmdq_error(item, "no command allowed"); + return (CMD_RETURN_ERROR); + } + if (args_has(args, 'R')) { + notify_hook(item, name); + return (CMD_RETURN_NORMAL); + } if (args_has(args, 'u')) { - if (cmd != NULL) { - cmdq_error(item, "command passed to unset hook: %s", - name); - return (CMD_RETURN_ERROR); - } hooks_remove(hooks, name); return (CMD_RETURN_NORMAL); } if (cmd == NULL) { - cmdq_error(item, "no command to set hook: %s", name); + cmdq_error(item, "no command given"); return (CMD_RETURN_ERROR); } cmdlist = cmd_string_parse(cmd, NULL, 0, &cause); -- cgit