mirror of https://github.com/tmux/tmux.git
Add set-hook -R to run a hook immediately (useful to set multiple hooks
to the same thing).pull/1395/head
parent
d254293a6d
commit
cc743dc296
|
@ -33,8 +33,8 @@ const struct cmd_entry cmd_set_hook_entry = {
|
||||||
.name = "set-hook",
|
.name = "set-hook",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "gt:u", 1, 2 },
|
.args = { "gRt:u", 1, 2 },
|
||||||
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
.usage = "[-gRu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
|
@ -101,18 +101,21 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
else
|
else
|
||||||
cmd = args->argv[1];
|
cmd = args->argv[1];
|
||||||
|
|
||||||
if (args_has(args, 'u')) {
|
if (cmd != NULL && (args_has(args, 'R') || args_has(args, 'u'))) {
|
||||||
if (cmd != NULL) {
|
cmdq_error(item, "no command allowed");
|
||||||
cmdq_error(item, "command passed to unset hook: %s",
|
|
||||||
name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
if (args_has(args, 'R')) {
|
||||||
|
notify_hook(item, name);
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
|
if (args_has(args, 'u')) {
|
||||||
hooks_remove(hooks, name);
|
hooks_remove(hooks, name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == NULL) {
|
if (cmd == NULL) {
|
||||||
cmdq_error(item, "no command to set hook: %s", name);
|
cmdq_error(item, "no command given");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||||
|
|
22
notify.c
22
notify.c
|
@ -36,7 +36,7 @@ struct notify_entry {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
notify_hook1(struct cmdq_item *item, struct notify_entry *ne)
|
||||||
{
|
{
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
struct hook *hook;
|
struct hook *hook;
|
||||||
|
@ -102,7 +102,7 @@ notify_callback(struct cmdq_item *item, void *data)
|
||||||
if (strcmp(ne->name, "session-window-changed") == 0)
|
if (strcmp(ne->name, "session-window-changed") == 0)
|
||||||
control_notify_session_window_changed(ne->session);
|
control_notify_session_window_changed(ne->session);
|
||||||
|
|
||||||
notify_hook(item, ne);
|
notify_hook1(item, ne);
|
||||||
|
|
||||||
if (ne->client != NULL)
|
if (ne->client != NULL)
|
||||||
server_client_unref(ne->client);
|
server_client_unref(ne->client);
|
||||||
|
@ -154,6 +154,24 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
|
||||||
cmdq_append(NULL, new_item);
|
cmdq_append(NULL, new_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
notify_hook(struct cmdq_item *item, const char *name)
|
||||||
|
{
|
||||||
|
struct notify_entry ne;
|
||||||
|
|
||||||
|
memset(&ne, 0, sizeof ne);
|
||||||
|
|
||||||
|
ne.name = name;
|
||||||
|
cmd_find_copy_state(&ne.fs, &item->target);
|
||||||
|
|
||||||
|
ne.client = item->client;
|
||||||
|
ne.session = item->target.s;
|
||||||
|
ne.window = item->target.w;
|
||||||
|
ne.pane = item->target.wp->id;
|
||||||
|
|
||||||
|
notify_hook1(item, &ne);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
notify_input(struct window_pane *wp, struct evbuffer *input)
|
notify_input(struct window_pane *wp, struct evbuffer *input)
|
||||||
{
|
{
|
||||||
|
|
12
tmux.1
12
tmux.1
|
@ -3452,12 +3452,14 @@ Run when a window is unlinked from a session.
|
||||||
Hooks are managed with these commands:
|
Hooks are managed with these commands:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo Ic set-hook
|
.It Xo Ic set-hook
|
||||||
.Op Fl gu
|
.Op Fl gRu
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
.Ar hook-name
|
.Ar hook-name
|
||||||
.Ar command
|
.Ar command
|
||||||
.Xc
|
.Xc
|
||||||
Sets (or with
|
Without
|
||||||
|
.Fl R,
|
||||||
|
sets (or with
|
||||||
.Fl u
|
.Fl u
|
||||||
unsets) hook
|
unsets) hook
|
||||||
.Ar hook-name
|
.Ar hook-name
|
||||||
|
@ -3473,6 +3475,12 @@ hooks (for
|
||||||
with
|
with
|
||||||
.Fl t ) .
|
.Fl t ) .
|
||||||
Like options, session hooks inherit from the global ones.
|
Like options, session hooks inherit from the global ones.
|
||||||
|
.Pp
|
||||||
|
With
|
||||||
|
.Fl R ,
|
||||||
|
run
|
||||||
|
.Ar hook-name
|
||||||
|
immediately.
|
||||||
.It Xo Ic show-hooks
|
.It Xo Ic show-hooks
|
||||||
.Op Fl g
|
.Op Fl g
|
||||||
.Op Fl t Ar target-session
|
.Op Fl t Ar target-session
|
||||||
|
|
1
tmux.h
1
tmux.h
|
@ -1594,6 +1594,7 @@ void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *,
|
||||||
struct cmd_find_state *, const char *, ...);
|
struct cmd_find_state *, const char *, ...);
|
||||||
|
|
||||||
/* notify.c */
|
/* notify.c */
|
||||||
|
void notify_hook(struct cmdq_item *, const char *);
|
||||||
void notify_input(struct window_pane *, struct evbuffer *);
|
void notify_input(struct window_pane *, struct evbuffer *);
|
||||||
void notify_client(const char *, struct client *);
|
void notify_client(const char *, struct client *);
|
||||||
void notify_session(const char *, struct session *);
|
void notify_session(const char *, struct session *);
|
||||||
|
|
Loading…
Reference in New Issue