2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *,
|
2016-10-10 21:51:39 +00:00
|
|
|
struct options *, int);
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
2016-10-10 21:51:39 +00:00
|
|
|
struct options *, enum options_table_scope);
|
2013-03-21 16:17:01 +00:00
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
const struct cmd_entry cmd_show_options_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "show-options",
|
|
|
|
.alias = "show",
|
|
|
|
|
|
|
|
.args = { "gqst:vw", 0, 1 },
|
|
|
|
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.tflag = CMD_WINDOW_CANFAIL,
|
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_show_options_exec
|
2009-06-01 22:58:49 +00:00
|
|
|
};
|
|
|
|
|
2011-01-04 02:03:41 +00:00
|
|
|
const struct cmd_entry cmd_show_window_options_entry = {
|
2015-12-13 21:53:57 +00:00
|
|
|
.name = "show-window-options",
|
|
|
|
.alias = "showw",
|
|
|
|
|
|
|
|
.args = { "gvt:", 0, 1 },
|
|
|
|
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
|
|
|
|
2015-12-14 00:31:54 +00:00
|
|
|
.tflag = CMD_WINDOW_CANFAIL,
|
|
|
|
|
2016-10-14 22:14:22 +00:00
|
|
|
.flags = CMD_AFTERHOOK,
|
2015-12-13 21:53:57 +00:00
|
|
|
.exec = cmd_show_options_exec
|
2011-01-04 02:03:41 +00:00
|
|
|
};
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-03-03 14:15:22 +00:00
|
|
|
struct args *args = self->args;
|
2016-10-16 19:04:05 +00:00
|
|
|
struct session *s = item->state.tflag.s;
|
|
|
|
struct winlink *wl = item->state.tflag.wl;
|
2016-03-03 14:15:22 +00:00
|
|
|
struct options *oo;
|
|
|
|
enum options_table_scope scope;
|
|
|
|
int quiet;
|
|
|
|
const char *target;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 's')) {
|
2015-10-27 15:58:42 +00:00
|
|
|
oo = global_options;
|
2015-11-20 12:01:19 +00:00
|
|
|
scope = OPTIONS_TABLE_SERVER;
|
2011-01-04 02:03:41 +00:00
|
|
|
} else if (args_has(self->args, 'w') ||
|
|
|
|
self->entry == &cmd_show_window_options_entry) {
|
2015-11-20 12:01:19 +00:00
|
|
|
scope = OPTIONS_TABLE_WINDOW;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2015-10-27 15:58:42 +00:00
|
|
|
oo = global_w_options;
|
2016-03-03 14:15:22 +00:00
|
|
|
else if (wl == NULL) {
|
|
|
|
target = args_get(args, 't');
|
|
|
|
if (target != NULL) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "no such window: %s", target);
|
2016-03-03 14:15:22 +00:00
|
|
|
} else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "no current window");
|
2016-03-03 14:15:22 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
} else
|
2015-10-27 15:58:42 +00:00
|
|
|
oo = wl->window->options;
|
2009-12-03 17:44:02 +00:00
|
|
|
} else {
|
2015-11-20 12:01:19 +00:00
|
|
|
scope = OPTIONS_TABLE_SESSION;
|
2011-01-04 00:42:46 +00:00
|
|
|
if (args_has(self->args, 'g'))
|
2015-10-27 15:58:42 +00:00
|
|
|
oo = global_s_options;
|
2016-03-03 14:15:22 +00:00
|
|
|
else if (s == NULL) {
|
|
|
|
target = args_get(args, 't');
|
|
|
|
if (target != NULL) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "no such session: %s", target);
|
2016-03-03 14:15:22 +00:00
|
|
|
} else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "no current session");
|
2016-03-03 14:15:22 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
} else
|
2015-10-27 15:58:42 +00:00
|
|
|
oo = s->options;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-25 10:04:04 +00:00
|
|
|
quiet = args_has(self->args, 'q');
|
|
|
|
if (args->argc == 0)
|
2016-10-16 19:04:05 +00:00
|
|
|
return (cmd_show_options_all(self, item, oo, scope));
|
2013-03-25 10:04:04 +00:00
|
|
|
else
|
2016-10-16 19:04:05 +00:00
|
|
|
return (cmd_show_options_one(self, item, oo, quiet));
|
2013-03-21 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_show_options_one(struct cmd *self, struct cmdq_item *item,
|
2013-03-25 10:04:04 +00:00
|
|
|
struct options *oo, int quiet)
|
2013-03-21 16:17:01 +00:00
|
|
|
{
|
|
|
|
struct args *args = self->args;
|
2014-04-17 07:43:20 +00:00
|
|
|
const char *name = args->argv[0];
|
2015-11-20 12:01:19 +00:00
|
|
|
const struct options_table_entry *oe;
|
2013-03-21 16:17:01 +00:00
|
|
|
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-25 10:04:04 +00:00
|
|
|
if (quiet)
|
|
|
|
return (CMD_RETURN_NORMAL);
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "unknown option: %s", name);
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
2012-02-25 12:57:42 +00:00
|
|
|
}
|
2013-03-21 16:17:01 +00:00
|
|
|
if (args_has(self->args, 'v'))
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s", o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s \"%s\"", o->name, o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
2015-11-20 12:01:19 +00:00
|
|
|
oe = NULL;
|
|
|
|
if (options_table_find(name, &oe) != 0) {
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "ambiguous option: %s", name);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
if (oe == NULL) {
|
2013-03-25 10:04:04 +00:00
|
|
|
if (quiet)
|
2015-11-20 12:01:19 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_error(item, "unknown option: %s", name);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
2014-04-17 07:43:20 +00:00
|
|
|
if (oe->style != NULL) {
|
|
|
|
name = oe->style;
|
|
|
|
goto retry;
|
|
|
|
}
|
2013-03-21 16:17:01 +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'))
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s", optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s %s", oe->name, optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2016-10-16 19:04:05 +00:00
|
|
|
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
|
|
|
|
struct options *oo, enum options_table_scope scope)
|
2013-03-21 16:17:01 +00:00
|
|
|
{
|
|
|
|
const struct options_table_entry *oe;
|
|
|
|
struct options_entry *o;
|
|
|
|
const char *optval;
|
2015-11-20 12:01:19 +00:00
|
|
|
int vflag;
|
2013-03-21 16:17:01 +00:00
|
|
|
|
2015-10-27 15:58:42 +00:00
|
|
|
o = options_first(oo);
|
|
|
|
while (o != NULL) {
|
2013-03-21 16:17:01 +00:00
|
|
|
if (*o->name == '@') {
|
|
|
|
if (args_has(self->args, 'v'))
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s", o->str);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s \"%s\"", o->name, o->str);
|
2012-02-25 12:57:42 +00:00
|
|
|
}
|
2015-10-27 15:58:42 +00:00
|
|
|
o = options_next(o);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-20 12:01:19 +00:00
|
|
|
vflag = args_has(self->args, 'v');
|
|
|
|
for (oe = options_table; oe->name != NULL; oe++) {
|
|
|
|
if (oe->style != NULL || oe->scope != scope)
|
2014-04-17 07:43:20 +00:00
|
|
|
continue;
|
2013-03-21 16:17:01 +00:00
|
|
|
if ((o = options_find1(oo, oe->name)) == NULL)
|
|
|
|
continue;
|
2015-11-20 12:01:19 +00:00
|
|
|
optval = options_table_print_entry(oe, o, vflag);
|
|
|
|
if (vflag)
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s", optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
else
|
2016-10-16 19:04:05 +00:00
|
|
|
cmdq_print(item, "%s %s", oe->name, optval);
|
2013-03-21 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|