Sync OpenBSD patchset 1032:

Allow a single option to be specified to show-options to show just that
option.
This commit is contained in:
Tiago Cunha 2012-03-03 09:16:52 +00:00
parent e0d2221879
commit 95f427c34e
5 changed files with 63 additions and 45 deletions

View File

@ -29,9 +29,6 @@
int cmd_set_option_exec(struct cmd *, struct cmd_ctx *); int cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
int cmd_set_option_find(const char *, const struct options_table_entry **,
const struct options_table_entry **);
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *, int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
const struct options_table_entry *, struct options *, const struct options_table_entry *, struct options *,
const char *); const char *);
@ -81,39 +78,6 @@ const struct cmd_entry cmd_set_window_option_entry = {
cmd_set_option_exec cmd_set_option_exec
}; };
/* Look for an option in all three tables. */
int
cmd_set_option_find(
const char *optstr, const struct options_table_entry **table,
const struct options_table_entry **oe)
{
static const struct options_table_entry *tables[] = {
server_options_table,
window_options_table,
session_options_table
};
const struct options_table_entry *oe_loop;
u_int i;
for (i = 0; i < nitems(tables); i++) {
for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
continue;
/* If already found, ambiguous. */
if (*oe != NULL)
return (-1);
*oe = oe_loop;
*table = tables[i];
/* Bail now if an exact match. */
if (strcmp((*oe)->name, optstr) == 0)
break;
}
}
return (0);
}
int int
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
@ -139,7 +103,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Find the option entry, try each table. */ /* Find the option entry, try each table. */
table = oe = NULL; table = oe = NULL;
if (cmd_set_option_find(optstr, &table, &oe) != 0) { if (options_table_find(optstr, &table, &oe) != 0) {
ctx->error(ctx, "ambiguous option: %s", optstr); ctx->error(ctx, "ambiguous option: %s", optstr);
return (-1); return (-1);
} }

View File

@ -31,8 +31,8 @@ int cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_options_entry = { const struct cmd_entry cmd_show_options_entry = {
"show-options", "show", "show-options", "show",
"gst:w", 0, 0, "gst:w", 0, 1,
"[-gsw] [-t target-session|target-window]", "[-gsw] [-t target-session|target-window] [option]",
0, 0,
NULL, NULL,
NULL, NULL,
@ -41,8 +41,8 @@ const struct cmd_entry cmd_show_options_entry = {
const struct cmd_entry cmd_show_window_options_entry = { const struct cmd_entry cmd_show_window_options_entry = {
"show-window-options", "showw", "show-window-options", "showw",
"gt:", 0, 0, "gt:", 0, 1,
"[-g] " CMD_TARGET_WINDOW_USAGE, "[-g] " CMD_TARGET_WINDOW_USAGE " [option]",
0, 0,
NULL, NULL,
NULL, NULL,
@ -86,12 +86,28 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
} }
} }
if (args->argc != 0) {
table = oe = NULL;
if (options_table_find(args->argv[0], &table, &oe) != 0) {
ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
return (-1);
}
if (oe == NULL) {
ctx->error(ctx, "unknown option: %s", args->argv[0]);
return (-1);
}
if ((o = options_find1(oo, oe->name)) == NULL)
return (0);
optval = options_table_print_entry(oe, o);
ctx->print(ctx, "%s %s", oe->name, optval);
} else {
for (oe = table; oe->name != NULL; oe++) { for (oe = table; oe->name != NULL; oe++) {
if ((o = options_find1(oo, oe->name)) == NULL) if ((o = options_find1(oo, oe->name)) == NULL)
continue; continue;
optval = options_table_print_entry(oe, o); optval = options_table_print_entry(oe, o);
ctx->print(ctx, "%s %s", oe->name, optval); ctx->print(ctx, "%s %s", oe->name, optval);
} }
}
return (0); return (0);
} }

View File

@ -731,3 +731,36 @@ options_table_print_entry(
} }
return (out); return (out);
} }
/* Find an option. */
int
options_table_find(
const char *optstr, const struct options_table_entry **table,
const struct options_table_entry **oe)
{
static const struct options_table_entry *tables[] = {
server_options_table,
window_options_table,
session_options_table
};
const struct options_table_entry *oe_loop;
u_int i;
for (i = 0; i < nitems(tables); i++) {
for (oe_loop = tables[i]; oe_loop->name != NULL; oe_loop++) {
if (strncmp(oe_loop->name, optstr, strlen(optstr)) != 0)
continue;
/* If already found, ambiguous. */
if (*oe != NULL)
return (-1);
*oe = oe_loop;
*table = tables[i];
/* Bail now if an exact match. */
if (strcmp((*oe)->name, optstr) == 0)
break;
}
}
return (0);
}

6
tmux.1
View File

@ -2626,9 +2626,10 @@ The default is off.
.It Xo Ic show-options .It Xo Ic show-options
.Op Fl gsw .Op Fl gsw
.Op Fl t Ar target-session | Ar target-window .Op Fl t Ar target-session | Ar target-window
.Op Ar option
.Xc .Xc
.D1 (alias: Ic show ) .D1 (alias: Ic show )
Show the window options with Show the window options (or a single window option if given) with
.Fl w .Fl w
(equivalent to (equivalent to
.Ic show-window-options ) , .Ic show-window-options ) ,
@ -2642,9 +2643,10 @@ is used.
.It Xo Ic show-window-options .It Xo Ic show-window-options
.Op Fl g .Op Fl g
.Op Fl t Ar target-window .Op Fl t Ar target-window
.Op Ar option
.Xc .Xc
.D1 (alias: Ic showw ) .D1 (alias: Ic showw )
List the window options for List the window options or a single option for
.Ar target-window , .Ar target-window ,
or the global window options if or the global window options if
.Fl g .Fl g

3
tmux.h
View File

@ -1415,6 +1415,9 @@ void options_table_populate_tree(
const struct options_table_entry *, struct options *); const struct options_table_entry *, struct options *);
const char *options_table_print_entry( const char *options_table_print_entry(
const struct options_table_entry *, struct options_entry *); const struct options_table_entry *, struct options_entry *);
int options_table_find(
const char *, const struct options_table_entry **,
const struct options_table_entry **);
/* job.c */ /* job.c */
extern struct joblist all_jobs; extern struct joblist all_jobs;