summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2018-07-04 12:30:52 +0000
committernicm <nicm@openbsd.org>2018-07-04 12:30:52 +0000
commit809c3f00605c588a0150d37b16de6e3f2ea09430 (patch)
tree44c8f36f1a26287040937913b442dbca231dfbe6
parentAdd pane focus hooks. (diff)
downloadwireguard-openbsd-809c3f00605c588a0150d37b16de6e3f2ea09430.tar.xz
wireguard-openbsd-809c3f00605c588a0150d37b16de6e3f2ea09430.zip
Add set-hook -R to run a hook immediately (useful to set multiple hooks
to the same thing).
-rw-r--r--usr.bin/tmux/cmd-set-hook.c21
-rw-r--r--usr.bin/tmux/notify.c24
-rw-r--r--usr.bin/tmux/tmux.114
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 46 insertions, 16 deletions
diff --git a/usr.bin/tmux/cmd-set-hook.c b/usr.bin/tmux/cmd-set-hook.c
index 6d6ac127321..20c72173f3c 100644
--- a/usr.bin/tmux/cmd-set-hook.c
+++ b/usr.bin/tmux/cmd-set-hook.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-hook.c,v 1.11 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-set-hook.c,v 1.12 2018/07/04 12:30:52 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -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);
diff --git a/usr.bin/tmux/notify.c b/usr.bin/tmux/notify.c
index 87f372c3732..947b6b10e7a 100644
--- a/usr.bin/tmux/notify.c
+++ b/usr.bin/tmux/notify.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notify.c,v 1.25 2017/08/30 10:33:57 nicm Exp $ */
+/* $OpenBSD: notify.c,v 1.26 2018/07/04 12:30:52 nicm Exp $ */
/*
* Copyright (c) 2012 George Nachman <tmux@georgester.com>
@@ -36,7 +36,7 @@ struct notify_entry {
};
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 hook *hook;
@@ -102,7 +102,7 @@ notify_callback(struct cmdq_item *item, void *data)
if (strcmp(ne->name, "session-window-changed") == 0)
control_notify_session_window_changed(ne->session);
- notify_hook(item, ne);
+ notify_hook1(item, ne);
if (ne->client != NULL)
server_client_unref(ne->client);
@@ -155,6 +155,24 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
}
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
notify_input(struct window_pane *wp, struct evbuffer *input)
{
struct client *c;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 678a374d00a..17af06607ca 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.603 2018/07/04 12:25:26 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.604 2018/07/04 12:30:52 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -3452,12 +3452,14 @@ 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 gu
+.Op Fl gRu
.Op Fl t Ar target-session
.Ar hook-name
.Ar command
.Xc
-Sets (or with
+Without
+.Fl R,
+sets (or with
.Fl u
unsets) hook
.Ar hook-name
@@ -3473,6 +3475,12 @@ hooks (for
with
.Fl t ) .
Like options, session hooks inherit from the global ones.
+.Pp
+With
+.Fl R ,
+run
+.Ar hook-name
+immediately.
.It Xo Ic show-hooks
.Op Fl g
.Op Fl t Ar target-session
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 00081ad62a1..1a63834b8d2 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.827 2018/07/04 09:44:07 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.828 2018/07/04 12:30:52 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1594,6 +1594,7 @@ void printflike(4, 5) hooks_insert(struct hooks *, struct cmdq_item *,
struct cmd_find_state *, const char *, ...);
/* notify.c */
+void notify_hook(struct cmdq_item *, const char *);
void notify_input(struct window_pane *, struct evbuffer *);
void notify_client(const char *, struct client *);
void notify_session(const char *, struct session *);