From 12ef3ceda13f9ae4c77384f98e6f145322971e69 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 4 Aug 2009 18:45:57 +0000 Subject: Add a -a flag to set-option and set-window-option to append to an existing string value, useful for terminal-overrides. --- options-cmd.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'options-cmd.c') diff --git a/options-cmd.c b/options-cmd.c index 6b7090bd..4cdd75d0 100644 --- a/options-cmd.c +++ b/options-cmd.c @@ -25,15 +25,26 @@ void set_option_string(struct cmd_ctx *ctx, struct options *oo, - const struct set_option_entry *entry, char *value) + const struct set_option_entry *entry, char *value, int append) { + char *oldvalue, *newvalue; + if (value == NULL) { ctx->error(ctx, "empty value"); return; } - options_set_string(oo, entry->name, "%s", value); - ctx->info(ctx, "set option: %s -> %s", entry->name, value); + if (append) { + oldvalue = options_get_string(oo, entry->name); + xasprintf(&newvalue, "%s%s", oldvalue, value); + } else + newvalue = value; + + options_set_string(oo, entry->name, "%s", newvalue); + ctx->info(ctx, "set option: %s -> %s", entry->name, newvalue); + + if (newvalue != value) + xfree(newvalue); } void -- cgit