summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-09-26 09:02:35 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-09-26 09:02:35 +0000
commit940ab56dc3e3ac584c55e3e14dc1e7de4d7b2351 (patch)
treeae13dde0c51b292b32c23d5fe96a5b846695b9a0 /usr.bin
parent3920b9d217ce9db970778b71e2ffe2510d753a81 (diff)
Support set -a (append) with user options, suggested by Xandor Schiefer.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-set-option.c27
-rw-r--r--usr.bin/tmux/options.c8
2 files changed, 22 insertions, 13 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index dfda82df2ef..faa1bc30851 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.96 2016/05/30 09:50:20 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.97 2016/09/26 09:02:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -227,10 +227,11 @@ enum cmd_retval
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
const char *valstr)
{
- struct args *args = self->args;
- struct session *s = cmdq->state.tflag.s;
- struct winlink *wl = cmdq->state.tflag.wl;
- struct options *oo;
+ struct args *args = self->args;
+ struct session *s = cmdq->state.tflag.s;
+ struct winlink *wl = cmdq->state.tflag.wl;
+ struct options *oo;
+ struct options_entry *o;
if (args_has(args, 's'))
oo = global_options;
@@ -262,18 +263,22 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char *optstr,
}
options_remove(oo, optstr);
} else {
- if (valstr == NULL) {
- cmdq_error(cmdq, "empty value");
- return (CMD_RETURN_ERROR);
- }
- if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
+ o = options_find1(oo, optstr);
+ if (args_has(args, 'o') && o != NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "already set: %s", optstr);
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
}
- options_set_string(oo, optstr, "%s", valstr);
+ if (valstr == NULL) {
+ cmdq_error(cmdq, "empty value");
+ return (CMD_RETURN_ERROR);
+ }
+ if (o != NULL && args_has(args, 'a'))
+ options_set_string(oo, optstr, "%s%s", o->str, valstr);
+ else
+ options_set_string(oo, optstr, "%s", valstr);
}
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c
index ab68a59da28..2e7185c5f75 100644
--- a/usr.bin/tmux/options.c
+++ b/usr.bin/tmux/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.18 2016/01/19 15:59:12 nicm Exp $ */
+/* $OpenBSD: options.c,v 1.19 2016/09/26 09:02:34 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -128,19 +128,23 @@ options_set_string(struct options *oo, const char *name, const char *fmt, ...)
{
struct options_entry *o;
va_list ap;
+ char *s;
+ s = NULL;
if ((o = options_find1(oo, name)) == NULL) {
o = xmalloc(sizeof *o);
o->name = xstrdup(name);
RB_INSERT(options_tree, &oo->tree, o);
memcpy(&o->style, &grid_default_cell, sizeof o->style);
} else if (o->type == OPTIONS_STRING)
- free(o->str);
+ s = o->str;
va_start(ap, fmt);
o->type = OPTIONS_STRING;
xvasprintf(&o->str, fmt, ap);
va_end(ap);
+
+ free(s);
return (o);
}