From 102cb7743545a1d86c53e7958fc56ec599ba0cd7 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 12 Feb 2013 20:12:10 +0000 Subject: [PATCH] Add -v to set and setw to show only option value. --- cmd-set-option.c | 2 +- cmd-show-options.c | 24 ++++++++++++++++-------- options-table.c | 12 ++++++++---- tmux.1 | 8 ++++++-- tmux.h | 11 +++++------ 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/cmd-set-option.c b/cmd-set-option.c index ca99a977..f9956252 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -234,7 +234,7 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx, if (o == NULL) return (-1); - s = options_table_print_entry(oe, o); + s = options_table_print_entry(oe, o, 0); if (!args_has(args, 'q')) ctx->info(ctx, "set option: %s -> %s", oe->name, s); return (0); diff --git a/cmd-show-options.c b/cmd-show-options.c index d37b791e..d396b101 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -31,8 +31,8 @@ enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_ctx *); const struct cmd_entry cmd_show_options_entry = { "show-options", "show", - "gst:w", 0, 1, - "[-gsw] [-t target-session|target-window] [option]", + "gst:vw", 0, 1, + "[-gsvw] [-t target-session|target-window] [option]", 0, NULL, NULL, @@ -41,8 +41,8 @@ const struct cmd_entry cmd_show_options_entry = { const struct cmd_entry cmd_show_window_options_entry = { "show-window-options", "showw", - "gt:", 0, 1, - "[-g] " CMD_TARGET_WINDOW_USAGE " [option]", + "gvt:", 0, 1, + "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]", 0, NULL, NULL, @@ -98,14 +98,22 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx) } if ((o = options_find1(oo, oe->name)) == NULL) return (CMD_RETURN_NORMAL); - optval = options_table_print_entry(oe, o); - ctx->print(ctx, "%s %s", oe->name, optval); + optval = options_table_print_entry(oe, o, + args_has(self->args, 'v')); + if (args_has(self->args, 'v')) + ctx->print(ctx, "%s", optval); + else + ctx->print(ctx, "%s %s", oe->name, optval); } else { for (oe = table; oe->name != NULL; oe++) { if ((o = options_find1(oo, oe->name)) == NULL) continue; - optval = options_table_print_entry(oe, o); - ctx->print(ctx, "%s %s", oe->name, optval); + optval = options_table_print_entry(oe, o, + args_has(self->args, 'v')); + if (args_has(self->args, 'v')) + ctx->print(ctx, "%s", optval); + else + ctx->print(ctx, "%s %s", oe->name, optval); } } diff --git a/options-table.c b/options-table.c index 83ec97f2..37b3b100 100644 --- a/options-table.c +++ b/options-table.c @@ -745,8 +745,8 @@ options_table_populate_tree( /* Print an option using its type from the table. */ const char * -options_table_print_entry( - const struct options_table_entry *oe, struct options_entry *o) +options_table_print_entry(const struct options_table_entry *oe, + struct options_entry *o, int no_quotes) { static char out[BUFSIZ]; const char *s; @@ -754,13 +754,17 @@ options_table_print_entry( *out = '\0'; switch (oe->type) { case OPTIONS_TABLE_STRING: - xsnprintf(out, sizeof out, "\"%s\"", o->str); + if (no_quotes) + xsnprintf(out, sizeof out, "%s", o->str); + else + xsnprintf(out, sizeof out, "\"%s\"", o->str); break; case OPTIONS_TABLE_NUMBER: xsnprintf(out, sizeof out, "%lld", o->num); break; case OPTIONS_TABLE_KEY: - xsnprintf(out, sizeof out, "%s", key_string_lookup_key(o->num)); + xsnprintf(out, sizeof out, "%s", + key_string_lookup_key(o->num)); break; case OPTIONS_TABLE_COLOUR: s = colour_tostring(o->num); diff --git a/tmux.1 b/tmux.1 index 5fc39792..2773de8e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -2869,7 +2869,7 @@ If this option is set, searches will wrap around the end of the pane contents. The default is on. .El .It Xo Ic show-options -.Op Fl gsw +.Op Fl gsvw .Op Fl t Ar target-session | Ar target-window .Op Ar option .Xc @@ -2885,8 +2885,10 @@ otherwise the session options for Global session or window options are listed if .Fl g is used. +.Fl v +shows only the option value, not the name. .It Xo Ic show-window-options -.Op Fl g +.Op Fl gv .Op Fl t Ar target-window .Op Ar option .Xc @@ -2896,6 +2898,8 @@ List the window options or a single option for or the global window options if .Fl g is used. +.Fl v +shows only the option value, not the name. .El .Sh FORMATS Certain commands accept the diff --git a/tmux.h b/tmux.h index 6c7c8532..78a5c81d 100644 --- a/tmux.h +++ b/tmux.h @@ -1568,12 +1568,11 @@ long long options_get_number(struct options *, const char *); extern const struct options_table_entry server_options_table[]; extern const struct options_table_entry session_options_table[]; extern const struct options_table_entry window_options_table[]; -void options_table_populate_tree( - const struct options_table_entry *, struct options *); -const char *options_table_print_entry( - const struct options_table_entry *, struct options_entry *); -int options_table_find( - const char *, const struct options_table_entry **, +void options_table_populate_tree(const struct options_table_entry *, + struct options *); +const char *options_table_print_entry(const struct options_table_entry *, + struct options_entry *, int); +int options_table_find(const char *, const struct options_table_entry **, const struct options_table_entry **); /* job.c */