summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-show-options.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-04-26 11:38:52 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-04-26 11:38:52 +0000
commit584b0b820080b312119c4f3889b3c3190195dc75 (patch)
treea7814fc11e7a8161308a43c4462562af1889073f /usr.bin/tmux/cmd-show-options.c
parente36c521bc8fb42ec39a478a61b68f80803204339 (diff)
Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and show-hooks remain but they are now variants of set-option and show-options. show-options now has a -H flag to show hooks (by default they are not shown).
Diffstat (limited to 'usr.bin/tmux/cmd-show-options.c')
-rw-r--r--usr.bin/tmux/cmd-show-options.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/usr.bin/tmux/cmd-show-options.c b/usr.bin/tmux/cmd-show-options.c
index 5d161991977..a4daac6cb02 100644
--- a/usr.bin/tmux/cmd-show-options.c
+++ b/usr.bin/tmux/cmd-show-options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-show-options.c,v 1.47 2019/04/25 18:18:55 nicm Exp $ */
+/* $OpenBSD: cmd-show-options.c,v 1.48 2019/04/26 11:38:51 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_show_options_entry = {
.name = "show-options",
.alias = "show",
- .args = { "gqst:vw", 0, 1 },
- .usage = "[-gqsvw] [-t target-session|target-window] [option]",
+ .args = { "gHqst:vw", 0, 1 },
+ .usage = "[-gHqsvw] [-t target-session|target-window] [option]",
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
@@ -61,6 +61,19 @@ const struct cmd_entry cmd_show_window_options_entry = {
.exec = cmd_show_options_exec
};
+const struct cmd_entry cmd_show_hooks_entry = {
+ .name = "show-hooks",
+ .alias = NULL,
+
+ .args = { "gt:", 0, 1 },
+ .usage = "[-g] " CMD_TARGET_SESSION_USAGE,
+
+ .target = { 't', CMD_FIND_SESSION, 0 },
+
+ .flags = CMD_AFTERHOOK,
+ .exec = cmd_show_options_exec
+};
+
static enum cmd_retval
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
{
@@ -162,15 +175,20 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
struct options_entry *o, int idx)
{
struct options_array_item *a;
- const char *name;
- char *value, *tmp, *escaped;
+ const char *name = options_name(o);
+ char *value, *tmp = NULL, *escaped;
if (idx != -1) {
- xasprintf(&tmp, "%s[%d]", options_name(o), idx);
+ xasprintf(&tmp, "%s[%d]", name, idx);
name = tmp;
} else {
if (options_isarray(o)) {
a = options_array_first(o);
+ if (a == NULL) {
+ if (!args_has(self->args, 'v'))
+ cmdq_print(item, "%s", name);
+ return;
+ }
while (a != NULL) {
idx = options_array_item_index(a);
cmd_show_options_print(self, item, o, idx);
@@ -178,8 +196,6 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
}
return;
}
- tmp = NULL;
- name = options_name(o);
}
value = options_tostring(o, idx, 0);
@@ -200,16 +216,28 @@ static enum cmd_retval
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
struct options *oo)
{
- struct options_entry *o;
- struct options_array_item *a;
- u_int idx;
+ struct options_entry *o;
+ struct options_array_item *a;
+ u_int idx;
+ int flags;
o = options_first(oo);
while (o != NULL) {
+ flags = options_table_entry(o)->flags;
+ if ((self->entry != &cmd_show_hooks_entry &&
+ !args_has(self->args, 'H') &&
+ (flags & OPTIONS_TABLE_IS_HOOK)) ||
+ (self->entry == &cmd_show_hooks_entry &&
+ (~flags & OPTIONS_TABLE_IS_HOOK))) {
+ o = options_next(o);
+ continue;
+ }
if (!options_isarray(o))
cmd_show_options_print(self, item, o, -1);
- else {
- a = options_array_first(o);
+ else if ((a = options_array_first(o)) == NULL) {
+ if (!args_has(self->args, 'v'))
+ cmdq_print(item, "%s", options_name(o));
+ } else {
while (a != NULL) {
idx = options_array_item_index(a);
cmd_show_options_print(self, item, o, idx);