summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-04-13 16:19:38 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-04-13 16:19:38 +0000
commit6af0448783bd9a0505e6c6248be39e08292148cd (patch)
tree087db4ecb5e92230f244a6205c1f3c18598981b3 /usr.bin/tmux
parentbbcd02d308c01313ff44ba41376758f81178d8ab (diff)
When parsing strings, put all commands in one group even if there are
newlines. This means that for example bind q { a \n b } and bind q "a ; b" are the same. Also log commands in different groups separated by ;; rather than ; (a command list like this should never be user visible).
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-parse.y23
-rw-r--r--usr.bin/tmux/cmd.c25
-rw-r--r--usr.bin/tmux/tmux.h3
3 files changed, 38 insertions, 13 deletions
diff --git a/usr.bin/tmux/cmd-parse.y b/usr.bin/tmux/cmd-parse.y
index 1fc52251477..93788c64c47 100644
--- a/usr.bin/tmux/cmd-parse.y
+++ b/usr.bin/tmux/cmd-parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-parse.y,v 1.24 2020/03/31 17:14:40 nicm Exp $ */
+/* $OpenBSD: cmd-parse.y,v 1.25 2020/04/13 16:19:37 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -700,15 +700,17 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds,
/*
* Parse each command into a command list. Create a new command list
- * for each line so they get a new group (so the queue knows which ones
- * to remove if a command fails when executed).
+ * for each line (unless the flag is set) so they get a new group (so
+ * the queue knows which ones to remove if a command fails when
+ * executed).
*/
result = cmd_list_new();
TAILQ_FOREACH(cmd, cmds, entry) {
log_debug("%s: %u %s", __func__, cmd->line, cmd->name);
cmd_log_argv(cmd->argc, cmd->argv, __func__);
- if (cmdlist == NULL || cmd->line != line) {
+ if (cmdlist == NULL ||
+ ((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
if (cmdlist != NULL) {
cmd_parse_print_commands(pi, line, cmdlist);
cmd_list_move(result, cmdlist);
@@ -775,6 +777,19 @@ cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi)
struct cmd_parse_result *
cmd_parse_from_string(const char *s, struct cmd_parse_input *pi)
{
+ struct cmd_parse_input input;
+
+ if (pi == NULL) {
+ memset(&input, 0, sizeof input);
+ pi = &input;
+ }
+
+ /*
+ * When parsing a string, put commands in one group even if there are
+ * multiple lines. This means { a \n b } is identical to "a ; b" when
+ * given as an argument to another command.
+ */
+ pi->flags |= CMD_PARSE_ONEGROUP;
return (cmd_parse_from_buffer(s, strlen(s), pi));
}
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index 8756c4f24f5..b4f0d863398 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.159 2020/04/13 15:55:51 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.160 2020/04/13 16:19:37 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -624,7 +624,7 @@ cmd_list_free(struct cmd_list *cmdlist)
char *
cmd_list_print(struct cmd_list *cmdlist, int escaped)
{
- struct cmd *cmd;
+ struct cmd *cmd, *next;
char *buf, *this;
size_t len;
@@ -634,15 +634,24 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
this = cmd_print(cmd);
- len += strlen(this) + 4;
+ len += strlen(this) + 6;
buf = xrealloc(buf, len);
strlcat(buf, this, len);
- if (TAILQ_NEXT(cmd, qentry) != NULL) {
- if (escaped)
- strlcat(buf, " \\; ", len);
- else
- strlcat(buf, " ; ", len);
+
+ next = TAILQ_NEXT(cmd, qentry);
+ if (next != NULL) {
+ if (cmd->group != next->group) {
+ if (escaped)
+ strlcat(buf, " \\;\\; ", len);
+ else
+ strlcat(buf, " ;; ", len);
+ } else {
+ if (escaped)
+ strlcat(buf, " \\; ", len);
+ else
+ strlcat(buf, " ; ", len);
+ }
}
free(this);
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 6d2c208c8f0..fd1f5ea12bd 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.987 2020/04/13 15:55:51 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.988 2020/04/13 16:19:37 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1370,6 +1370,7 @@ struct cmd_parse_input {
#define CMD_PARSE_PARSEONLY 0x2
#define CMD_PARSE_NOALIAS 0x4
#define CMD_PARSE_VERBOSE 0x8
+#define CMD_PARSE_ONEGROUP 0x10
const char *file;
u_int line;