summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-set-option.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2017-01-24 19:11:47 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2017-01-24 19:11:47 +0000
commit38c599a96818f72492019b9f38af1421b37c2e65 (patch)
treefa082f2a0717481d28dcb8de815d0a39ae3cadc7 /usr.bin/tmux/cmd-set-option.c
parent4856937ff10a8987fbb03b4e1d9db5a2f7e2d300 (diff)
If given an array option without an index either show or set all items,
and support -a for array options. Allow the separator for set to be specified in the options table (will be used for backwards compatibility later).
Diffstat (limited to 'usr.bin/tmux/cmd-set-option.c')
-rw-r--r--usr.bin/tmux/cmd-set-option.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 2f3b068015f..7b9d511b2fc 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.107 2017/01/16 14:49:14 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.108 2017/01/24 19:11:46 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -160,11 +160,17 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
cmdq_error(item, "not an array: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
- } else {
- if (*name != '@' && options_array_size(parent, NULL) != -1) {
- cmdq_error(item, "is an array: %s", args->argv[0]);
- return (CMD_RETURN_ERROR);
+ } else if (*name != '@' && options_array_size(parent, NULL) != -1) {
+ if (value == NULL) {
+ cmdq_error(item, "empty value");
+ return (-1);
}
+ if (o == NULL)
+ o = options_empty(oo, options_table_entry(parent));
+ if (!args_has(args, 'a'))
+ options_array_clear(o);
+ options_array_assign(o, value);
+ return (CMD_RETURN_NORMAL);
}
/* With -o, check this option is not already set. */
@@ -197,7 +203,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
else
options_remove(o);
} else
- options_array_set(o, idx, NULL);
+ options_array_set(o, idx, NULL, 0);
} else if (*name == '@')
options_set_string(oo, name, args_has(args, 'a'), "%s", value);
else if (idx == -1) {
@@ -207,7 +213,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
} else {
if (o == NULL)
o = options_empty(oo, options_table_entry(parent));
- if (options_array_set(o, idx, value) != 0) {
+ if (options_array_set(o, idx, value, 1) != 0) {
cmdq_error(item, "invalid index: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}