aboutsummaryrefslogtreecommitdiff
path: root/cmd-set-option.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-set-option.c')
-rw-r--r--cmd-set-option.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 23b45230..e04aa7ff 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -69,10 +69,10 @@ const struct cmd_entry cmd_set_hook_entry = {
.name = "set-hook",
.alias = NULL,
- .args = { "agRt:u", 1, 2 },
- .usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]",
+ .args = { "agpRt:uw", 1, 2 },
+ .usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]",
- .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
+ .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
.flags = CMD_AFTERHOOK,
.exec = cmd_set_option_exec
@@ -81,12 +81,11 @@ const struct cmd_entry cmd_set_hook_entry = {
static enum cmd_retval
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
{
- struct args *args = self->args;
+ struct args *args = cmd_get_args(self);
int append = args_has(args, 'a');
- struct cmd_find_state *fs = &item->target;
- struct client *c, *loop;
- struct session *s = fs->s;
- struct winlink *wl = fs->wl;
+ struct cmd_find_state *target = cmdq_get_target(item);
+ struct client *loop;
+ struct session *s = target->s;
struct window *w;
struct window_pane *wp;
struct options *oo;
@@ -94,16 +93,14 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
char *name, *argument, *value = NULL, *cause;
int window, idx, already, error, ambiguous;
int scope;
- struct style *sy;
- window = (self->entry == &cmd_set_window_option_entry);
+ window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
/* Expand argument. */
- c = cmd_find_client(item, NULL, 1);
- argument = format_single(item, args->argv[0], c, s, wl, NULL);
+ argument = format_single_from_target(item, args->argv[0]);
/* If set-hook -R, fire the hook straight away. */
- if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) {
+ if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) {
notify_hook(item, argument);
free(argument);
return (CMD_RETURN_NORMAL);
@@ -123,12 +120,13 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
if (args->argc < 2)
value = NULL;
else if (args_has(args, 'F'))
- value = format_single(item, args->argv[1], c, s, wl, NULL);
+ value = format_single_from_target(item, args->argv[1]);
else
value = xstrdup(args->argv[1]);
/* Get the scope and table for the option .*/
- scope = options_scope_from_name(args, window, name, fs, &oo, &cause);
+ scope = options_scope_from_name(args, window, name, target, &oo,
+ &cause);
if (scope == OPTIONS_TABLE_NONE) {
if (args_has(args, 'q'))
goto out;
@@ -233,16 +231,6 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
tty_keys_build(&loop->tty);
}
}
- if (strcmp(name, "status-fg") == 0 || strcmp(name, "status-bg") == 0) {
- sy = options_get_style(oo, "status-style");
- sy->gc.fg = options_get_number(oo, "status-fg");
- sy->gc.bg = options_get_number(oo, "status-bg");
- }
- if (strcmp(name, "status-style") == 0) {
- sy = options_get_style(oo, "status-style");
- options_set_number(oo, "status-fg", sy->gc.fg);
- options_set_number(oo, "status-bg", sy->gc.bg);
- }
if (strcmp(name, "status") == 0 ||
strcmp(name, "status-interval") == 0)
status_timer_start_all();
@@ -284,16 +272,38 @@ fail:
}
static int
+cmd_set_option_check_string(const struct options_table_entry *oe,
+ const char *value, char **cause)
+{
+ struct style sy;
+
+ if (strcmp(oe->name, "default-shell") == 0 && !checkshell(value)) {
+ xasprintf(cause, "not a suitable shell: %s", value);
+ return (-1);
+ }
+ if (oe->pattern != NULL && fnmatch(oe->pattern, value, 0) != 0) {
+ xasprintf(cause, "value is invalid: %s", value);
+ return (-1);
+ }
+ if ((oe->flags & OPTIONS_TABLE_IS_STYLE) &&
+ strstr(value, "#{") == NULL &&
+ style_parse(&sy, &grid_default_cell, value) != 0) {
+ xasprintf(cause, "invalid style: %s", value);
+ return (-1);
+ }
+ return (0);
+}
+
+static int
cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
struct options_entry *parent, const char *value)
{
const struct options_table_entry *oe;
- struct args *args = self->args;
+ struct args *args = cmd_get_args(self);
int append = args_has(args, 'a');
- struct options_entry *o;
long long number;
const char *errstr, *new;
- char *old;
+ char *old, *cause;
key_code key;
oe = options_table_entry(parent);
@@ -309,10 +319,12 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
old = xstrdup(options_get_string(oo, oe->name));
options_set_string(oo, oe->name, append, "%s", value);
new = options_get_string(oo, oe->name);
- if (oe->pattern != NULL && fnmatch(oe->pattern, new, 0) != 0) {
+ if (cmd_set_option_check_string(oe, new, &cause) != 0) {
+ cmdq_error(item, "%s", cause);
+ free(cause);
+
options_set_string(oo, oe->name, 0, "%s", old);
free(old);
- cmdq_error(item, "value is invalid: %s", value);
return (-1);
}
free(old);
@@ -344,13 +356,6 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
return (cmd_set_option_flag(item, oe, oo, value));
case OPTIONS_TABLE_CHOICE:
return (cmd_set_option_choice(item, oe, oo, value));
- case OPTIONS_TABLE_STYLE:
- o = options_set_style(oo, oe->name, append, value);
- if (o == NULL) {
- cmdq_error(item, "bad style: %s", value);
- return (-1);
- }
- return (0);
case OPTIONS_TABLE_COMMAND:
break;
}