summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2016-10-16 19:55:52 +0000
committernicm <nicm>2016-10-16 19:55:52 +0000
commitd15d54c2c8e6b95695169442eb2a27d814efc078 (patch)
tree034728a41518f6f200b30b3869e131908bf7a5b5
parent3f35b5299fb2c08637aa12757185e5b82eeb3fc1 (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.
-rw-r--r--notify.c28
-rw-r--r--tmux.18
2 files changed, 28 insertions, 8 deletions
diff --git a/notify.c b/notify.c
index 20709e53..49d7e32f 100644
--- a/notify.c
+++ b/notify.c
@@ -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);
}
diff --git a/tmux.1 b/tmux.1
index 88697bcf..e13b5573 100644
--- a/tmux.1
+++ b/tmux.1
@@ -3244,6 +3244,10 @@ Run when the program running in a pane exits, but
is on so the pane has not closed.
.It pane-exited
Run when the program running in a pane exits.
+.It session-created
+Run when a new session created.
+.It session-closed
+Run when a session closed.
.It session-renamed
Run when a session is renamed.
.It window-renamed
@@ -3467,6 +3471,10 @@ The following variables are available, where appropriate:
.It Li "history_limit" Ta "" Ta "Maximum window history lines"
.It Li "history_size" Ta "" Ta "Size of history in bytes"
.It Li "hook" Ta "" Ta "Name of running hook, if any"
+.It Li "hook_session" Ta "" Ta "ID of session where hook was run, if any"
+.It Li "hook_session_name" Ta "" Ta "Name of session where hook was run, if any"
+.It Li "hook_window" Ta "" Ta "ID of window where hook was run, if any"
+.It Li "hook_window_name" Ta "" Ta "Name of window where hook was run, if any"
.It Li "host" Ta "#H" Ta "Hostname of local host"
.It Li "host_short" Ta "#h" Ta "Hostname of local host (no domain name)"
.It Li "insert_flag" Ta "" Ta "Pane insert flag"