mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Copy the code to infer the option type to show-options and document it.
This commit is contained in:
parent
3f189945d8
commit
5b9211d827
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
||||||
|
|
||||||
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *,
|
static void cmd_show_options_print(struct cmd *, struct cmdq_item *,
|
||||||
struct options *);
|
struct options_entry *, int);
|
||||||
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
||||||
struct options *);
|
struct options *);
|
||||||
|
|
||||||
@ -66,23 +66,95 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
{
|
{
|
||||||
struct args *args = self->args;
|
struct args *args = self->args;
|
||||||
struct cmd_find_state *fs = &item->target;
|
struct cmd_find_state *fs = &item->target;
|
||||||
|
struct client *c = cmd_find_client(item, NULL, 1);
|
||||||
|
struct session *s = item->target.s;
|
||||||
|
struct winlink *wl = item->target.wl;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
enum options_table_scope scope;
|
enum options_table_scope scope;
|
||||||
char *cause;
|
char *argument, *name = NULL, *cause;
|
||||||
int window;
|
const char *target;
|
||||||
|
int window, idx, ambiguous;
|
||||||
|
struct options_entry *o;
|
||||||
|
|
||||||
window = (self->entry == &cmd_show_window_options_entry);
|
window = (self->entry == &cmd_show_window_options_entry);
|
||||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
if (args->argc == 0) {
|
||||||
|
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||||
|
return (cmd_show_options_all(self, item, oo));
|
||||||
|
}
|
||||||
|
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||||
|
|
||||||
|
name = options_match(argument, &idx, &ambiguous);
|
||||||
|
if (name == NULL) {
|
||||||
|
if (args_has(args, 'q'))
|
||||||
|
goto fail;
|
||||||
|
if (ambiguous)
|
||||||
|
cmdq_error(item, "ambiguous option: %s", argument);
|
||||||
|
else
|
||||||
|
cmdq_error(item, "invalid option: %s", argument);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
if (*name == '@')
|
||||||
|
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||||
|
else {
|
||||||
|
if (options_get_only(global_options, name) != NULL)
|
||||||
|
scope = OPTIONS_TABLE_SERVER;
|
||||||
|
else if (options_get_only(global_s_options, name) != NULL)
|
||||||
|
scope = OPTIONS_TABLE_SESSION;
|
||||||
|
else if (options_get_only(global_w_options, name) != NULL)
|
||||||
|
scope = OPTIONS_TABLE_WINDOW;
|
||||||
|
else {
|
||||||
|
scope = OPTIONS_TABLE_NONE;
|
||||||
|
xasprintf(&cause, "unknown option: %s", argument);
|
||||||
|
}
|
||||||
|
if (scope == OPTIONS_TABLE_SERVER)
|
||||||
|
oo = global_options;
|
||||||
|
else if (scope == OPTIONS_TABLE_SESSION) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = global_s_options;
|
||||||
|
else if (s == NULL) {
|
||||||
|
target = args_get(args, 't');
|
||||||
|
if (target != NULL) {
|
||||||
|
cmdq_error(item, "no such session: %s",
|
||||||
|
target);
|
||||||
|
} else
|
||||||
|
cmdq_error(item, "no current session");
|
||||||
|
goto fail;
|
||||||
|
} else
|
||||||
|
oo = s->options;
|
||||||
|
} else if (scope == OPTIONS_TABLE_WINDOW) {
|
||||||
|
if (args_has(self->args, 'g'))
|
||||||
|
oo = global_w_options;
|
||||||
|
else if (wl == NULL) {
|
||||||
|
target = args_get(args, 't');
|
||||||
|
if (target != NULL) {
|
||||||
|
cmdq_error(item, "no such window: %s",
|
||||||
|
target);
|
||||||
|
} else
|
||||||
|
cmdq_error(item, "no current window");
|
||||||
|
goto fail;
|
||||||
|
} else
|
||||||
|
oo = wl->window->options;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
if (scope == OPTIONS_TABLE_NONE) {
|
||||||
|
if (args_has(args, 'q'))
|
||||||
|
goto fail;
|
||||||
cmdq_error(item, "%s", cause);
|
cmdq_error(item, "%s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
goto fail;
|
||||||
}
|
}
|
||||||
|
o = options_get_only(oo, name);
|
||||||
|
if (o != NULL)
|
||||||
|
cmd_show_options_print(self, item, o, idx);
|
||||||
|
|
||||||
if (args->argc == 0)
|
free(name);
|
||||||
return (cmd_show_options_all(self, item, oo));
|
free(argument);
|
||||||
else
|
return (CMD_RETURN_NORMAL);
|
||||||
return (cmd_show_options_one(self, item, oo));
|
|
||||||
|
fail:
|
||||||
|
free(name);
|
||||||
|
free(argument);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -123,44 +195,6 @@ cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
|||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
|
||||||
cmd_show_options_one(struct cmd *self, struct cmdq_item *item,
|
|
||||||
struct options *oo)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
int idx, ambiguous;
|
|
||||||
char *name;
|
|
||||||
|
|
||||||
name = format_single(item, args->argv[0], c, s, wl, NULL);
|
|
||||||
o = options_match_get(oo, name, &idx, 1, &ambiguous);
|
|
||||||
if (o == NULL) {
|
|
||||||
if (args_has(args, 'q')) {
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
if (ambiguous) {
|
|
||||||
cmdq_error(item, "ambiguous option: %s", name);
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (*name != '@' &&
|
|
||||||
options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) {
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
cmdq_error(item, "unknown option: %s", name);
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
cmd_show_options_print(self, item, o, idx);
|
|
||||||
free(name);
|
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
|
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
|
||||||
struct options *oo)
|
struct options *oo)
|
||||||
|
17
tmux.1
17
tmux.1
@ -2488,9 +2488,17 @@ command),
|
|||||||
a server option with
|
a server option with
|
||||||
.Fl s ,
|
.Fl s ,
|
||||||
otherwise a session option.
|
otherwise a session option.
|
||||||
|
If the option is not a user option,
|
||||||
|
.Fl w
|
||||||
|
and
|
||||||
|
.Fl s
|
||||||
|
are unnecessary -
|
||||||
|
.Nm
|
||||||
|
will infer the type from the option name.
|
||||||
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.
|
||||||
|
.Pp
|
||||||
.Fl F
|
.Fl F
|
||||||
expands formats in the option value.
|
expands formats in the option value.
|
||||||
The
|
The
|
||||||
@ -3384,6 +3392,15 @@ the server options with
|
|||||||
.Fl s ,
|
.Fl s ,
|
||||||
otherwise the session options for
|
otherwise the session options for
|
||||||
.Ar target session .
|
.Ar target session .
|
||||||
|
If
|
||||||
|
.Ar option
|
||||||
|
is given and is not a user option,
|
||||||
|
.Fl w
|
||||||
|
and
|
||||||
|
.Fl s
|
||||||
|
are unnecessary -
|
||||||
|
.Nm
|
||||||
|
will infer the type from the option name.
|
||||||
Global session or window options are listed if
|
Global session or window options are listed if
|
||||||
.Fl g
|
.Fl g
|
||||||
is used.
|
is used.
|
||||||
|
Loading…
Reference in New Issue
Block a user