mirror of
https://github.com/tmux/tmux.git
synced 2025-03-28 01:08:53 +00:00
Expand formats in option names and add -F flag to do so in option values as well.
This commit is contained in:
parent
0e3c5ebe1a
commit
b519551153
@ -42,8 +42,8 @@ const struct cmd_entry cmd_set_option_entry = {
|
|||||||
.name = "set-option",
|
.name = "set-option",
|
||||||
.alias = "set",
|
.alias = "set",
|
||||||
|
|
||||||
.args = { "agoqst:uw", 1, 2 },
|
.args = { "aFgoqst:uw", 1, 2 },
|
||||||
.usage = "[-agosquw] [-t target-window] option [value]",
|
.usage = "[-aFgosquw] [-t target-window] option [value]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
|||||||
.name = "set-window-option",
|
.name = "set-window-option",
|
||||||
.alias = "setw",
|
.alias = "setw",
|
||||||
|
|
||||||
.args = { "agoqt:u", 1, 2 },
|
.args = { "aFgoqt:u", 1, 2 },
|
||||||
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
@ -70,33 +70,38 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
int append = args_has(args, 'a');
|
int append = args_has(args, 'a');
|
||||||
struct cmd_find_state *fs = &item->target;
|
struct cmd_find_state *fs = &item->target;
|
||||||
|
struct client *c, *loop;
|
||||||
struct session *s = fs->s;
|
struct session *s = fs->s;
|
||||||
struct winlink *wl = fs->wl;
|
struct winlink *wl = fs->wl;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct client *c;
|
|
||||||
enum options_table_scope scope;
|
enum options_table_scope scope;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct options_entry *parent, *o;
|
struct options_entry *parent, *o;
|
||||||
char *name;
|
char *name, *argument, *value = NULL, *cause;
|
||||||
const char *value, *target;
|
const char *target;
|
||||||
int window, idx, already, error, ambiguous;
|
int window, idx, already, error, ambiguous;
|
||||||
char *cause;
|
|
||||||
|
/* Expand argument. */
|
||||||
|
c = cmd_find_client(item, NULL, 1);
|
||||||
|
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||||
|
|
||||||
/* Parse option name and index. */
|
/* Parse option name and index. */
|
||||||
name = options_match(args->argv[0], &idx, &ambiguous);
|
name = options_match(argument, &idx, &ambiguous);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q'))
|
||||||
return (CMD_RETURN_NORMAL);
|
goto out;
|
||||||
if (ambiguous)
|
if (ambiguous)
|
||||||
cmdq_error(item, "ambiguous option: %s", args->argv[0]);
|
cmdq_error(item, "ambiguous option: %s", argument);
|
||||||
else
|
else
|
||||||
cmdq_error(item, "invalid option: %s", args->argv[0]);
|
cmdq_error(item, "invalid option: %s", argument);
|
||||||
return (CMD_RETURN_ERROR);
|
goto fail;
|
||||||
}
|
}
|
||||||
if (args->argc < 2)
|
if (args->argc < 2)
|
||||||
value = NULL;
|
value = NULL;
|
||||||
|
else if (args_has(args, 'F'))
|
||||||
|
value = format_single(item, args->argv[1], c, s, wl, NULL);
|
||||||
else
|
else
|
||||||
value = args->argv[1];
|
value = xstrdup(args->argv[1]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out the scope: for user options it comes from the arguments,
|
* Figure out the scope: for user options it comes from the arguments,
|
||||||
@ -114,12 +119,12 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
scope = OPTIONS_TABLE_WINDOW;
|
scope = OPTIONS_TABLE_WINDOW;
|
||||||
else {
|
else {
|
||||||
scope = OPTIONS_TABLE_NONE;
|
scope = OPTIONS_TABLE_NONE;
|
||||||
xasprintf(&cause, "unknown option: %s", args->argv[0]);
|
xasprintf(&cause, "unknown option: %s", argument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
if (scope == OPTIONS_TABLE_NONE) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q'))
|
||||||
return (CMD_RETURN_NORMAL);
|
goto out;
|
||||||
cmdq_error(item, "%s", cause);
|
cmdq_error(item, "%s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -159,7 +164,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
/* Check that array options and indexes match up. */
|
/* Check that array options and indexes match up. */
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
if (*name == '@' || options_array_size(parent, NULL) == -1) {
|
if (*name == '@' || options_array_size(parent, NULL) == -1) {
|
||||||
cmdq_error(item, "not an array: %s", args->argv[0]);
|
cmdq_error(item, "not an array: %s", argument);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,8 +181,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
if (already) {
|
if (already) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q'))
|
||||||
return (CMD_RETURN_NORMAL);
|
goto out;
|
||||||
cmdq_error(item, "already set: %s", args->argv[0]);
|
cmdq_error(item, "already set: %s", argument);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +222,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
options_array_clear(o);
|
options_array_clear(o);
|
||||||
options_array_assign(o, value);
|
options_array_assign(o, value);
|
||||||
} else if (options_array_set(o, idx, value, append) != 0) {
|
} else if (options_array_set(o, idx, value, append) != 0) {
|
||||||
cmdq_error(item, "invalid index: %s", args->argv[0]);
|
cmdq_error(item, "invalid index: %s", argument);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,8 +237,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(name, "key-table") == 0) {
|
if (strcmp(name, "key-table") == 0) {
|
||||||
TAILQ_FOREACH(c, &clients, entry)
|
TAILQ_FOREACH(loop, &clients, entry)
|
||||||
server_client_set_key_table(c, NULL);
|
server_client_set_key_table(loop, NULL);
|
||||||
}
|
}
|
||||||
if (strcmp(name, "status") == 0 ||
|
if (strcmp(name, "status") == 0 ||
|
||||||
strcmp(name, "status-interval") == 0)
|
strcmp(name, "status-interval") == 0)
|
||||||
@ -257,15 +262,20 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
* anyway.
|
* anyway.
|
||||||
*/
|
*/
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
TAILQ_FOREACH(loop, &clients, entry) {
|
||||||
if (c->session != NULL)
|
if (loop->session != NULL)
|
||||||
server_redraw_client(c);
|
server_redraw_client(loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(argument);
|
||||||
|
free(value);
|
||||||
free(name);
|
free(name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
free(argument);
|
||||||
|
free(value);
|
||||||
free(name);
|
free(name);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
@ -128,25 +128,36 @@ cmd_show_options_one(struct cmd *self, struct cmdq_item *item,
|
|||||||
struct options *oo)
|
struct options *oo)
|
||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
|
struct session *s = item->target.s;
|
||||||
|
struct winlink *wl = item->target.wl;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
int idx, ambiguous;
|
int idx, ambiguous;
|
||||||
const char *name = args->argv[0];
|
char *name;
|
||||||
|
|
||||||
|
name = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||||
o = options_match_get(oo, name, &idx, 1, &ambiguous);
|
o = options_match_get(oo, name, &idx, 1, &ambiguous);
|
||||||
if (o == NULL) {
|
if (o == NULL) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q')) {
|
||||||
|
free(name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
if (ambiguous) {
|
if (ambiguous) {
|
||||||
cmdq_error(item, "ambiguous option: %s", name);
|
cmdq_error(item, "ambiguous option: %s", name);
|
||||||
|
free(name);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if (*name != '@' &&
|
if (*name != '@' &&
|
||||||
options_match_get(oo, name, &idx, 0, &ambiguous) != NULL)
|
options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) {
|
||||||
|
free(name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
cmdq_error(item, "unknown option: %s", name);
|
cmdq_error(item, "unknown option: %s", name);
|
||||||
|
free(name);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
cmd_show_options_print(self, item, o, idx);
|
cmd_show_options_print(self, item, o, idx);
|
||||||
|
free(name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
tmux.1
7
tmux.1
@ -2331,7 +2331,7 @@ abc123
|
|||||||
Commands which set options are as follows:
|
Commands which set options are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo Ic set-option
|
.It Xo Ic set-option
|
||||||
.Op Fl agoqsuw
|
.Op Fl aFgoqsuw
|
||||||
.Op Fl t Ar target-session | Ar target-window
|
.Op Fl t Ar target-session | Ar target-window
|
||||||
.Ar option Ar value
|
.Ar option Ar value
|
||||||
.Xc
|
.Xc
|
||||||
@ -2347,6 +2347,8 @@ otherwise a session option.
|
|||||||
If
|
If
|
||||||
.Fl g
|
.Fl g
|
||||||
is given, the global session or window option is set.
|
is given, the global session or window option is set.
|
||||||
|
.Fl F
|
||||||
|
expands formats in the option value.
|
||||||
The
|
The
|
||||||
.Fl u
|
.Fl u
|
||||||
flag unsets an option, so a session inherits the option from the global
|
flag unsets an option, so a session inherits the option from the global
|
||||||
@ -2897,7 +2899,7 @@ The default is
|
|||||||
.Ql \ -_@ .
|
.Ql \ -_@ .
|
||||||
.El
|
.El
|
||||||
.It Xo Ic set-window-option
|
.It Xo Ic set-window-option
|
||||||
.Op Fl agoqu
|
.Op Fl aFgoqu
|
||||||
.Op Fl t Ar target-window
|
.Op Fl t Ar target-window
|
||||||
.Ar option Ar value
|
.Ar option Ar value
|
||||||
.Xc
|
.Xc
|
||||||
@ -2905,6 +2907,7 @@ The default is
|
|||||||
Set a window option.
|
Set a window option.
|
||||||
The
|
The
|
||||||
.Fl a ,
|
.Fl a ,
|
||||||
|
.Fl F ,
|
||||||
.Fl g ,
|
.Fl g ,
|
||||||
.Fl o ,
|
.Fl o ,
|
||||||
.Fl q
|
.Fl q
|
||||||
|
Loading…
Reference in New Issue
Block a user