summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/notify.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-10-16 19:55:53 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-10-16 19:55:53 +0000
commit172f48a476b4f195184bd22ea8cc9aeaf2c86d21 (patch)
tree13a8b95e35e25f4f99665d8c17d3753ee8a2faf2 /usr.bin/tmux/notify.c
parenteee049be7f597be67ef17a07e8e7a5a6e38bddbb (diff)
Add hook_session and hook_window formats to get information on the
affected session or window when a hook fires. Enable session-created and session-closed hooks now that that is available.
Diffstat (limited to 'usr.bin/tmux/notify.c')
-rw-r--r--usr.bin/tmux/notify.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index 3d26168eaab..4d809e373e7 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.16 2016/10/16 19:36:37 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.17 2016/10/16 19:55:52 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -41,8 +41,8 @@ static const char *notify_hooks[] = {
"window-renamed",
NULL, /* "attached-session-changed", */
"session-renamed",
- NULL, /* "session-created", */
- NULL, /* "session-closed" */
+ "session-created",
+ "session-closed"
};
struct notify_entry {
@@ -60,18 +60,20 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne)
struct cmd_find_state fs;
struct hook *hook;
struct cmdq_item *new_item;
+ struct session *s = ne->session;
+ struct window *w = ne->window;
name = notify_hooks[ne->type];
if (name == NULL)
return;
cmd_find_clear_state(&fs, NULL, 0);
- if (ne->session != NULL && ne->window != NULL)
- cmd_find_from_session_window(&fs, ne->session, ne->window);
- else if (ne->window != NULL)
- cmd_find_from_window(&fs, ne->window);
- else if (ne->session != NULL)
- cmd_find_from_session(&fs, ne->session);
+ if (s != NULL && w != NULL)
+ cmd_find_from_session_window(&fs, s, w);
+ else if (w != NULL)
+ cmd_find_from_window(&fs, w);
+ else if (s != NULL && session_alive(s))
+ cmd_find_from_session(&fs, s);
else
cmd_find_current(&fs, item, CMD_FIND_QUIET);
if (cmd_find_empty_state(&fs) || !cmd_find_valid_state(&fs))
@@ -84,6 +86,16 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne)
new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS);
cmdq_format(new_item, "hook", "%s", name);
+
+ if (s != NULL) {
+ cmdq_format(new_item, "hook_session", "$%u", s->id);
+ cmdq_format(new_item, "hook_session_name", "%s", s->name);
+ }
+ if (w != NULL) {
+ cmdq_format(new_item, "hook_window", "@%u", w->id);
+ cmdq_format(new_item, "hook_window_name", "%s", w->name);
+ }
+
cmdq_insert_after(item, new_item);
}