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>
|
2017-01-15 20:48:41 +00:00
|
|
|
#include <vis.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2019-04-18 12:22:07 +00:00
|
|
|
static void cmd_show_options_print(struct cmd *, struct cmdq_item *,
|
2019-06-20 07:10:56 +00:00
|
|
|
struct options_entry *, int, int);
|
2016-10-16 19:04:05 +00:00
|
|
|
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
2019-06-20 11:59:59 +00:00
|
|
|
int, struct options *);
|
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",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "AgHpqst:vw", 0, 1, NULL },
|
2019-06-20 11:59:59 +00:00
|
|
|
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",
|
2015-12-13 21:53:57 +00:00
|
|
|
|
2019-06-20 11:59:59 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
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",
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "gvt:", 0, 1, NULL },
|
2015-12-13 21:53:57 +00:00
|
|
|
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
|
|
|
|
2017-04-22 10:22:39 +00:00
|
|
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
2015-12-14 00:31:54 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-04-26 11:38:51 +00:00
|
|
|
const struct cmd_entry cmd_show_hooks_entry = {
|
|
|
|
.name = "show-hooks",
|
|
|
|
.alias = NULL,
|
|
|
|
|
2021-08-21 10:22:38 +00:00
|
|
|
.args = { "gpt:w", 0, 1, NULL },
|
2020-04-13 07:25:33 +00:00
|
|
|
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
2019-04-26 11:38:51 +00:00
|
|
|
|
2020-04-13 07:25:33 +00:00
|
|
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
2019-04-26 11:38:51 +00:00
|
|
|
|
|
|
|
.flags = CMD_AFTERHOOK,
|
|
|
|
.exec = cmd_show_options_exec
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2020-04-13 10:59:58 +00:00
|
|
|
struct cmd_find_state *target = cmdq_get_target(item);
|
2016-03-03 14:15:22 +00:00
|
|
|
struct options *oo;
|
2019-04-18 12:22:07 +00:00
|
|
|
char *argument, *name = NULL, *cause;
|
2019-06-20 11:59:59 +00:00
|
|
|
int window, idx, ambiguous, parent, scope;
|
2019-04-18 12:22:07 +00:00
|
|
|
struct options_entry *o;
|
2017-01-15 20:48:41 +00:00
|
|
|
|
2020-04-13 08:26:27 +00:00
|
|
|
window = (cmd_get_entry(self) == &cmd_show_window_options_entry);
|
2019-06-20 07:41:29 +00:00
|
|
|
|
2021-08-20 19:50:16 +00:00
|
|
|
if (args_count(args) == 0) {
|
2020-04-13 10:59:58 +00:00
|
|
|
scope = options_scope_from_flags(args, window, target, &oo,
|
|
|
|
&cause);
|
2019-05-22 18:58:31 +00:00
|
|
|
if (scope == OPTIONS_TABLE_NONE) {
|
|
|
|
if (args_has(args, 'q'))
|
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
|
|
|
return (CMD_RETURN_ERROR);
|
|
|
|
}
|
2019-06-20 07:10:56 +00:00
|
|
|
return (cmd_show_options_all(self, item, scope, oo));
|
2019-05-12 18:18:30 +00:00
|
|
|
}
|
2021-08-20 19:50:16 +00:00
|
|
|
argument = format_single_from_target(item, args_string(args, 0));
|
2019-04-18 12:22:07 +00:00
|
|
|
|
|
|
|
name = options_match(argument, &idx, &ambiguous);
|
|
|
|
if (name == NULL) {
|
|
|
|
if (args_has(args, 'q'))
|
2022-02-14 09:10:48 +00:00
|
|
|
goto out;
|
2019-04-18 12:22:07 +00:00
|
|
|
if (ambiguous)
|
|
|
|
cmdq_error(item, "ambiguous option: %s", argument);
|
|
|
|
else
|
|
|
|
cmdq_error(item, "invalid option: %s", argument);
|
|
|
|
goto fail;
|
|
|
|
}
|
2020-04-13 10:59:58 +00:00
|
|
|
scope = options_scope_from_name(args, window, name, target, &oo,
|
|
|
|
&cause);
|
2017-01-15 20:48:41 +00:00
|
|
|
if (scope == OPTIONS_TABLE_NONE) {
|
2019-04-18 12:22:07 +00:00
|
|
|
if (args_has(args, 'q'))
|
2022-02-14 09:10:48 +00:00
|
|
|
goto out;
|
2017-01-15 20:48:41 +00:00
|
|
|
cmdq_error(item, "%s", cause);
|
|
|
|
free(cause);
|
2019-04-18 12:22:07 +00:00
|
|
|
goto fail;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2019-04-18 12:22:07 +00:00
|
|
|
o = options_get_only(oo, name);
|
2019-06-20 07:10:56 +00:00
|
|
|
if (args_has(args, 'A') && o == NULL) {
|
|
|
|
o = options_get(oo, name);
|
|
|
|
parent = 1;
|
|
|
|
} else
|
|
|
|
parent = 0;
|
2019-04-18 12:22:07 +00:00
|
|
|
if (o != NULL)
|
2019-06-20 07:10:56 +00:00
|
|
|
cmd_show_options_print(self, item, o, idx, parent);
|
2021-10-21 08:23:48 +00:00
|
|
|
else if (*name == '@') {
|
|
|
|
if (args_has(args, 'q'))
|
2022-02-14 09:10:48 +00:00
|
|
|
goto out;
|
2021-10-21 08:23:48 +00:00
|
|
|
cmdq_error(item, "invalid option: %s", argument);
|
|
|
|
goto fail;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2022-02-14 09:10:48 +00:00
|
|
|
out:
|
2019-04-18 12:22:07 +00:00
|
|
|
free(name);
|
|
|
|
free(argument);
|
|
|
|
return (CMD_RETURN_NORMAL);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
free(name);
|
|
|
|
free(argument);
|
|
|
|
return (CMD_RETURN_ERROR);
|
2017-01-15 20:48:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
2019-06-20 07:10:56 +00:00
|
|
|
struct options_entry *o, int idx, int parent)
|
2017-01-15 20:48:41 +00:00
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2019-03-18 11:58:40 +00:00
|
|
|
struct options_array_item *a;
|
2019-04-26 11:38:51 +00:00
|
|
|
const char *name = options_name(o);
|
|
|
|
char *value, *tmp = NULL, *escaped;
|
2017-01-15 20:48:41 +00:00
|
|
|
|
|
|
|
if (idx != -1) {
|
2019-04-26 11:38:51 +00:00
|
|
|
xasprintf(&tmp, "%s[%d]", name, idx);
|
2017-01-15 20:48:41 +00:00
|
|
|
name = tmp;
|
|
|
|
} else {
|
2020-05-16 16:02:24 +00:00
|
|
|
if (options_is_array(o)) {
|
2019-03-18 11:58:40 +00:00
|
|
|
a = options_array_first(o);
|
2019-04-26 11:38:51 +00:00
|
|
|
if (a == NULL) {
|
2020-04-13 08:26:27 +00:00
|
|
|
if (!args_has(args, 'v'))
|
2019-04-26 11:38:51 +00:00
|
|
|
cmdq_print(item, "%s", name);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-18 11:58:40 +00:00
|
|
|
while (a != NULL) {
|
|
|
|
idx = options_array_item_index(a);
|
2019-06-20 07:10:56 +00:00
|
|
|
cmd_show_options_print(self, item, o, idx,
|
|
|
|
parent);
|
2019-03-18 11:58:40 +00:00
|
|
|
a = options_array_next(a);
|
2017-01-24 19:11:46 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-01-15 20:48:41 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 16:02:24 +00:00
|
|
|
value = options_to_string(o, idx, 0);
|
2020-04-13 08:26:27 +00:00
|
|
|
if (args_has(args, 'v'))
|
2017-01-15 20:48:41 +00:00
|
|
|
cmdq_print(item, "%s", value);
|
2020-05-16 16:02:24 +00:00
|
|
|
else if (options_is_string(o)) {
|
2019-05-23 18:33:53 +00:00
|
|
|
escaped = args_escape(value);
|
2019-06-20 07:10:56 +00:00
|
|
|
if (parent)
|
|
|
|
cmdq_print(item, "%s* %s", name, escaped);
|
|
|
|
else
|
|
|
|
cmdq_print(item, "%s %s", name, escaped);
|
2017-01-15 20:48:41 +00:00
|
|
|
free(escaped);
|
2019-06-20 07:10:56 +00:00
|
|
|
} else {
|
|
|
|
if (parent)
|
|
|
|
cmdq_print(item, "%s* %s", name, value);
|
|
|
|
else
|
|
|
|
cmdq_print(item, "%s %s", name, value);
|
|
|
|
}
|
2019-04-25 18:18:55 +00:00
|
|
|
free(value);
|
2017-01-15 20:48:41 +00:00
|
|
|
|
|
|
|
free(tmp);
|
2013-03-21 16:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:51:39 +00:00
|
|
|
static enum cmd_retval
|
2019-06-20 11:59:59 +00:00
|
|
|
cmd_show_options_all(struct cmd *self, struct cmdq_item *item, int scope,
|
|
|
|
struct options *oo)
|
2013-03-21 16:17:01 +00:00
|
|
|
{
|
2020-04-13 08:26:27 +00:00
|
|
|
struct args *args = cmd_get_args(self);
|
2019-06-20 07:10:56 +00:00
|
|
|
const struct options_table_entry *oe;
|
2019-04-30 18:02:03 +00:00
|
|
|
struct options_entry *o;
|
|
|
|
struct options_array_item *a;
|
2019-06-20 11:59:59 +00:00
|
|
|
const char *name;
|
2019-04-30 18:02:03 +00:00
|
|
|
u_int idx;
|
2019-06-20 07:10:56 +00:00
|
|
|
int parent;
|
|
|
|
|
2020-12-28 09:40:27 +00:00
|
|
|
if (cmd_get_entry(self) != &cmd_show_hooks_entry) {
|
|
|
|
o = options_first(oo);
|
|
|
|
while (o != NULL) {
|
|
|
|
if (options_table_entry(o) == NULL)
|
|
|
|
cmd_show_options_print(self, item, o, -1, 0);
|
|
|
|
o = options_next(o);
|
|
|
|
}
|
2019-06-20 13:39:17 +00:00
|
|
|
}
|
2019-06-20 07:10:56 +00:00
|
|
|
for (oe = options_table; oe->name != NULL; oe++) {
|
2019-06-20 11:59:59 +00:00
|
|
|
if (~oe->scope & scope)
|
2019-06-20 07:10:56 +00:00
|
|
|
continue;
|
2013-03-21 16:17:01 +00:00
|
|
|
|
2020-04-13 08:26:27 +00:00
|
|
|
if ((cmd_get_entry(self) != &cmd_show_hooks_entry &&
|
|
|
|
!args_has(args, 'H') &&
|
2019-04-30 18:02:03 +00:00
|
|
|
(oe->flags & OPTIONS_TABLE_IS_HOOK)) ||
|
2020-04-13 08:26:27 +00:00
|
|
|
(cmd_get_entry(self) == &cmd_show_hooks_entry &&
|
2020-04-09 13:56:46 +00:00
|
|
|
(~oe->flags & OPTIONS_TABLE_IS_HOOK)))
|
2019-04-26 11:38:51 +00:00
|
|
|
continue;
|
2019-06-20 07:10:56 +00:00
|
|
|
|
|
|
|
o = options_get_only(oo, oe->name);
|
|
|
|
if (o == NULL) {
|
2020-04-13 08:26:27 +00:00
|
|
|
if (!args_has(args, 'A'))
|
2019-06-20 07:10:56 +00:00
|
|
|
continue;
|
|
|
|
o = options_get(oo, oe->name);
|
|
|
|
if (o == NULL)
|
|
|
|
continue;
|
|
|
|
parent = 1;
|
|
|
|
} else
|
|
|
|
parent = 0;
|
|
|
|
|
2020-05-16 16:02:24 +00:00
|
|
|
if (!options_is_array(o))
|
2019-06-20 07:10:56 +00:00
|
|
|
cmd_show_options_print(self, item, o, -1, parent);
|
2019-04-26 11:38:51 +00:00
|
|
|
else if ((a = options_array_first(o)) == NULL) {
|
2020-04-13 08:26:27 +00:00
|
|
|
if (!args_has(args, 'v')) {
|
2019-06-20 11:59:59 +00:00
|
|
|
name = options_name(o);
|
2019-06-20 07:10:56 +00:00
|
|
|
if (parent)
|
2019-06-20 11:59:59 +00:00
|
|
|
cmdq_print(item, "%s*", name);
|
2019-06-20 07:10:56 +00:00
|
|
|
else
|
2019-06-20 11:59:59 +00:00
|
|
|
cmdq_print(item, "%s", name);
|
2019-06-20 07:10:56 +00:00
|
|
|
}
|
2019-04-26 11:38:51 +00:00
|
|
|
} else {
|
2019-03-18 11:58:40 +00:00
|
|
|
while (a != NULL) {
|
|
|
|
idx = options_array_item_index(a);
|
2019-06-20 11:59:59 +00:00
|
|
|
cmd_show_options_print(self, item, o, idx,
|
|
|
|
parent);
|
2019-03-18 11:58:40 +00:00
|
|
|
a = options_array_next(a);
|
2017-01-15 20:48:41 +00:00
|
|
|
}
|
2012-02-25 12:57:42 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2012-07-11 07:10:15 +00:00
|
|
|
return (CMD_RETURN_NORMAL);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|