mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 16:46:18 +00:00 
			
		
		
		
	Change so that the appropriate hooks for windows and panes belong to
pane/window options rather than all being session options. This is useful for example to create a pane that is automatically closed on some condition. From Anindya Mukherjee.
This commit is contained in:
		@@ -69,10 +69,10 @@ const struct cmd_entry cmd_set_hook_entry = {
 | 
			
		||||
	.name = "set-hook",
 | 
			
		||||
	.alias = NULL,
 | 
			
		||||
 | 
			
		||||
	.args = { "agRt:u", 1, 2 },
 | 
			
		||||
	.usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]",
 | 
			
		||||
	.args = { "agpRt:uw", 1, 2 },
 | 
			
		||||
	.usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]",
 | 
			
		||||
 | 
			
		||||
	.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
 | 
			
		||||
	.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
 | 
			
		||||
 | 
			
		||||
	.flags = CMD_AFTERHOOK,
 | 
			
		||||
	.exec = cmd_set_option_exec
 | 
			
		||||
 
 | 
			
		||||
@@ -65,10 +65,10 @@ const struct cmd_entry cmd_show_hooks_entry = {
 | 
			
		||||
	.name = "show-hooks",
 | 
			
		||||
	.alias = NULL,
 | 
			
		||||
 | 
			
		||||
	.args = { "gt:", 0, 1 },
 | 
			
		||||
	.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
 | 
			
		||||
	.args = { "gpt:w", 0, 1 },
 | 
			
		||||
	.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
 | 
			
		||||
 | 
			
		||||
	.target = { 't', CMD_FIND_SESSION, 0 },
 | 
			
		||||
	.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
 | 
			
		||||
 | 
			
		||||
	.flags = CMD_AFTERHOOK,
 | 
			
		||||
	.exec = cmd_show_options_exec
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								notify.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								notify.c
									
									
									
									
									
								
							@@ -76,6 +76,14 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
 | 
			
		||||
	else
 | 
			
		||||
		oo = fs.s->options;
 | 
			
		||||
	o = options_get(oo, ne->name);
 | 
			
		||||
	if (o == NULL && fs.wp != NULL) {
 | 
			
		||||
		oo = fs.wp->options;
 | 
			
		||||
		o = options_get(oo, ne->name);
 | 
			
		||||
	}
 | 
			
		||||
	if (o == NULL && fs.wl != NULL) {
 | 
			
		||||
		oo = fs.wl->window->options;
 | 
			
		||||
		o = options_get(oo, ne->name);
 | 
			
		||||
	}
 | 
			
		||||
	if (o == NULL)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -140,7 +140,7 @@ static const char *options_table_status_format_default[] = {
 | 
			
		||||
	OPTIONS_TABLE_STATUS_FORMAT1, OPTIONS_TABLE_STATUS_FORMAT2, NULL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Helper for hook options. */
 | 
			
		||||
/* Helpers for hook options. */
 | 
			
		||||
#define OPTIONS_TABLE_HOOK(hook_name, default_value) \
 | 
			
		||||
	{ .name = hook_name, \
 | 
			
		||||
	  .type = OPTIONS_TABLE_COMMAND, \
 | 
			
		||||
@@ -150,6 +150,24 @@ static const char *options_table_status_format_default[] = {
 | 
			
		||||
	  .separator = "" \
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#define OPTIONS_TABLE_PANE_HOOK(hook_name, default_value) \
 | 
			
		||||
	{ .name = hook_name, \
 | 
			
		||||
	  .type = OPTIONS_TABLE_COMMAND, \
 | 
			
		||||
	  .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, \
 | 
			
		||||
	  .flags = OPTIONS_TABLE_IS_ARRAY|OPTIONS_TABLE_IS_HOOK, \
 | 
			
		||||
	  .default_str = default_value,	\
 | 
			
		||||
	  .separator = "" \
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
#define OPTIONS_TABLE_WINDOW_HOOK(hook_name, default_value) \
 | 
			
		||||
	{ .name = hook_name, \
 | 
			
		||||
	  .type = OPTIONS_TABLE_COMMAND, \
 | 
			
		||||
	  .scope = OPTIONS_TABLE_WINDOW, \
 | 
			
		||||
	  .flags = OPTIONS_TABLE_IS_ARRAY|OPTIONS_TABLE_IS_HOOK, \
 | 
			
		||||
	  .default_str = default_value,	\
 | 
			
		||||
	  .separator = "" \
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
/* Top-level options. */
 | 
			
		||||
const struct options_table_entry options_table[] = {
 | 
			
		||||
	/* Server options. */
 | 
			
		||||
@@ -851,21 +869,21 @@ const struct options_table_entry options_table[] = {
 | 
			
		||||
	OPTIONS_TABLE_HOOK("client-detached", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("client-resized", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("client-session-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-died", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-exited", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-focus-in", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-focus-out", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-mode-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("pane-set-clipboard", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-died", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-exited", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-focus-in", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-focus-out", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-mode-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_PANE_HOOK("pane-set-clipboard", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("session-closed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("session-created", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("session-renamed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("session-window-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("window-layout-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("window-linked", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("window-pane-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("window-renamed", ""),
 | 
			
		||||
	OPTIONS_TABLE_HOOK("window-unlinked", ""),
 | 
			
		||||
	OPTIONS_TABLE_WINDOW_HOOK("window-layout-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_WINDOW_HOOK("window-linked", ""),
 | 
			
		||||
	OPTIONS_TABLE_WINDOW_HOOK("window-pane-changed", ""),
 | 
			
		||||
	OPTIONS_TABLE_WINDOW_HOOK("window-renamed", ""),
 | 
			
		||||
	OPTIONS_TABLE_WINDOW_HOOK("window-unlinked", ""),
 | 
			
		||||
 | 
			
		||||
	{ .name = NULL }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										29
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								tmux.1
									
									
									
									
									
								
							@@ -3897,6 +3897,7 @@ hook and there are a number of hooks not associated with commands.
 | 
			
		||||
.Pp
 | 
			
		||||
Hooks are stored as array options, members of the array are executed in
 | 
			
		||||
order when the hook is triggered.
 | 
			
		||||
Like options different hooks may be global or belong to a session, window or pane.
 | 
			
		||||
Hooks may be configured with the
 | 
			
		||||
.Ic set-hook
 | 
			
		||||
or
 | 
			
		||||
@@ -3989,8 +3990,8 @@ Run when a window is unlinked from a session.
 | 
			
		||||
Hooks are managed with these commands:
 | 
			
		||||
.Bl -tag -width Ds
 | 
			
		||||
.It Xo Ic set-hook
 | 
			
		||||
.Op Fl agRu
 | 
			
		||||
.Op Fl t Ar target-session
 | 
			
		||||
.Op Fl agpRuw
 | 
			
		||||
.Op Fl t Ar target-pane
 | 
			
		||||
.Ar hook-name
 | 
			
		||||
.Ar command
 | 
			
		||||
.Xc
 | 
			
		||||
@@ -4002,18 +4003,8 @@ unsets) hook
 | 
			
		||||
.Ar hook-name
 | 
			
		||||
to
 | 
			
		||||
.Ar command .
 | 
			
		||||
If
 | 
			
		||||
.Fl g
 | 
			
		||||
is given,
 | 
			
		||||
.Em hook-name
 | 
			
		||||
is added to the global list of hooks, otherwise it is added to the session
 | 
			
		||||
hooks (for
 | 
			
		||||
.Ar target-session
 | 
			
		||||
with
 | 
			
		||||
.Fl t ) .
 | 
			
		||||
.Fl a
 | 
			
		||||
appends to a hook.
 | 
			
		||||
Like options, session hooks inherit from the global ones.
 | 
			
		||||
The flags are the same as for
 | 
			
		||||
.Ic set-option .
 | 
			
		||||
.Pp
 | 
			
		||||
With
 | 
			
		||||
.Fl R ,
 | 
			
		||||
@@ -4021,12 +4012,12 @@ run
 | 
			
		||||
.Ar hook-name
 | 
			
		||||
immediately.
 | 
			
		||||
.It Xo Ic show-hooks
 | 
			
		||||
.Op Fl g
 | 
			
		||||
.Op Fl t Ar target-session
 | 
			
		||||
.Op Fl gpw
 | 
			
		||||
.Op Fl t Ar target-pane
 | 
			
		||||
.Xc
 | 
			
		||||
Shows the global list of hooks with
 | 
			
		||||
.Fl g ,
 | 
			
		||||
otherwise the session hooks.
 | 
			
		||||
Shows hooks.
 | 
			
		||||
The flags are the same as for
 | 
			
		||||
.Ic show-options .
 | 
			
		||||
.El
 | 
			
		||||
.Sh MOUSE SUPPORT
 | 
			
		||||
If the
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user