2014-11-08 12:27:43 +00:00
|
|
|
/* $OpenBSD$ */
|
2008-06-15 08:01:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show options.
|
|
|
|
*/
|
|
|
|
|
2013-02-23 22:25:58 +00:00
|
|
|
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
|
2008-06-15 08:01:54 +00:00
|
|
|
|
2013-02-23 22:25:58 +00:00
|
|
|
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
|
2013-03-04 09:00:24 +00:00
|
|
|
struct options *, int);
|
2013-02-23 22:25:58 +00:00
|
|
|
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
|
2013-02-13 09:54:24 +00:00
|
|
|
const struct options_table_entry *, struct options *);
|
|
|
|
|
2008-06-15 08:01:54 +00:00
|
|
|
const struct cmd_entry cmd_show_options_entry = {
|
|
|
|
"show-options", "show",
|
2013-03-04 09:00:24 +00:00
|
|
|
"gqst:vw", 0, 1,
|
|
|
|
"[-gqsvw] [-t target-session|target-window] [option]",
|
2011-01-07 14:45:34 +00:00
|
|
|
0,
|
|
|
|
cmd_show_options_exec
|
2008-06-15 08:01:54 +00:00
|
|
|
};
|
|
|
|
|
2011-01-07 15:02:38 +00:00
|
|
|
const struct cmd_entry cmd_show_window_options_entry = {
|
|
|
|
"show-window-options", "showw",
|
2013-02-12 20:12:10 +00:00
|
|
|
"gvt:", 0, 1,
|
|
|
|
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
2011-01-07 15:02:38 +00:00
|
|
|
0,
|
|
|
|
cmd_show_options_exec
|
|
|
|
};
|
|
|
|
|
2012-07-11 19:37:32 +00:00
|
|
|
enum cmd_retval
|
2013-02-23 22:25:58 +00:00
|
|
|
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
|
2008-06-15 08:01:54 +00:00
|
|
|
{
|
2011-01-07 14:45:34 +00:00
|
|
|
struct args *args = self->args;
|
2011-01-03 23:52:38 +00:00
|
|
|
struct session *s;
|
|
|
|
struct winlink *wl;
|
2013-02-13 09:54:24 +00:00
|
|
|
const struct options_table_entry *table;
|
2011-01-03 23:52:38 +00:00
|
|
|
struct options *oo;
|
2013-03-04 09:00:24 +00:00
|
|
|
int quiet;
|
2008-06-15 08:01:54 +00:00
|
|
|
|
2011-01-07 14:45:34 +00:00
|
|
|
if (args_has(self->args, 's')) {
|
2009-12-10 16:59:02 +00:00
|
|
|
oo = &global_options;
|
2011-01-03 23:52:38 +00:00
|
|
|
table = server_options_table;
|
2011-01-07 15:02:38 +00:00
|
|
|
} else if (args_has(self->args, 'w') ||
|
|
|
|
self->entry == &cmd_show_window_options_entry) {
|
2011-01-03 23:52:38 +00:00
|
|
|
table = window_options_table;
|
2011-01-07 14:45:34 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2009-12-04 22:11:23 +00:00
|
|
|
oo = &global_w_options;
|
|
|
|
else {
|
2013-02-23 22:25:58 +00:00
|
|
|
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
|
2009-12-04 22:11:23 +00:00
|
|
|
if (wl == NULL)
|
2012-07-11 19:37:32 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-12-04 22:11:23 +00:00
|
|
|
oo = &wl->window->options;
|
|
|
|
}
|
|
|
|
} else {
|
2011-01-03 23:52:38 +00:00
|
|
|
table = session_options_table;
|
2011-01-07 14:45:34 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2009-12-04 22:11:23 +00:00
|
|
|
oo = &global_s_options;
|
|
|
|
else {
|
2013-02-23 22:25:58 +00:00
|
|
|
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
|
2009-12-04 22:11:23 +00:00
|
|
|
if (s == NULL)
|
2012-07-11 19:37:32 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2009-12-04 22:11:23 +00:00
|
|
|
oo = &s->options;
|
|
|
|
}
|
2008-12-08 16:19:51 +00:00
|
|
|
}
|
2008-06-15 08:01:54 +00:00
|
|
|
|
2013-03-04 09:00:24 +00:00
|
|
|
quiet = args_has(self->args, 'q');
|
|
|
|
if (args->argc == 0)
|
2013-02-23 22:25:58 +00:00
|
|
|
return (cmd_show_options_all(self, cmdq, table, oo));
|
2013-03-04 09:00:24 +00:00
|
|
|
else
|
|
|
|
return (cmd_show_options_one(self, cmdq, oo, quiet));
|
2013-02-13 09:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum cmd_retval
|
2013-02-23 22:25:58 +00:00
|
|
|
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
|
2013-03-04 09:00:24 +00:00
|
|
|
struct options *oo, int quiet)
|
2013-02-13 09:54:24 +00:00
|
|
|
{
|
|
|
|
struct args *args = self->args;
|
2014-04-17 07:43:20 +00:00
|
|
|
const char *name = args->argv[0];
|
2013-02-13 09:54:24 +00:00
|
|
|
const struct options_table_entry *table, *oe;
|
|
|
|
struct options_entry *o;
|
|
|
|
const char *optval;
|
|
|
|
|
2014-04-17 07:43:20 +00:00
|
|
|
retry:
|
|
|
|
if (*name == '@') {
|
|
|
|
if ((o = options_find1(oo, name)) == NULL) {
|
2013-03-04 09:00:24 +00:00
|
|
|
if (quiet)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
2014-04-17 07:43:20 +00:00
|
|
|
cmdq_error(cmdq, "unknown option: %s", name);
|
2012-07-11 19:37:32 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-03-03 09:16:52 +00:00
|
|
|
}
|
2013-02-13 09:54:24 +00:00
|
|
|
if (args_has(self->args, 'v'))
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s", o->str);
|
2013-02-13 09:54:24 +00:00
|
|
|
else
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
2013-02-13 09:54:24 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
table = oe = NULL;
|
2014-04-17 07:43:20 +00:00
|
|
|
if (options_table_find(name, &table, &oe) != 0) {
|
|
|
|
cmdq_error(cmdq, "ambiguous option: %s", name);
|
2013-02-13 09:54:24 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
if (oe == NULL) {
|
2013-03-04 09:00:24 +00:00
|
|
|
if (quiet)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
2014-04-17 07:43:20 +00:00
|
|
|
cmdq_error(cmdq, "unknown option: %s", name);
|
2013-02-13 09:54:24 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
2014-04-17 07:43:20 +00:00
|
|
|
if (oe->style != NULL) {
|
|
|
|
name = oe->style;
|
|
|
|
goto retry;
|
|
|
|
}
|
2013-02-13 09:54:24 +00:00
|
|
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
|
|
|
|
if (args_has(self->args, 'v'))
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s", optval);
|
2013-02-13 09:54:24 +00:00
|
|
|
else
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
2013-02-13 09:54:24 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum cmd_retval
|
2013-02-23 22:25:58 +00:00
|
|
|
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
|
2013-02-13 09:54:24 +00:00
|
|
|
const struct options_table_entry *table, struct options *oo)
|
|
|
|
{
|
|
|
|
const struct options_table_entry *oe;
|
|
|
|
struct options_entry *o;
|
|
|
|
const char *optval;
|
|
|
|
|
|
|
|
RB_FOREACH(o, options_tree, &oo->tree) {
|
|
|
|
if (*o->name == '@') {
|
|
|
|
if (args_has(self->args, 'v'))
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s", o->str);
|
2013-02-13 09:54:24 +00:00
|
|
|
else
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
|
2013-02-13 09:54:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (oe = table; oe->name != NULL; oe++) {
|
2014-04-17 07:43:20 +00:00
|
|
|
if (oe->style != NULL)
|
|
|
|
continue;
|
2011-01-03 23:52:38 +00:00
|
|
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
2013-02-13 09:54:24 +00:00
|
|
|
continue;
|
2013-02-12 20:12:10 +00:00
|
|
|
optval = options_table_print_entry(oe, o,
|
|
|
|
args_has(self->args, 'v'));
|
|
|
|
if (args_has(self->args, 'v'))
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s", optval);
|
2013-02-12 20:12:10 +00:00
|
|
|
else
|
2013-02-23 22:25:58 +00:00
|
|
|
cmdq_print(cmdq, "%s %s", oe->name, optval);
|
2008-06-15 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 19:37:32 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2008-06-15 08:01:54 +00:00
|
|
|
}
|