From d7a2b52da8187204de8f8b3c18b770da5205b115 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 5 Jun 2026 08:04:03 +0000 Subject: [PATCH] Add a way to quote for command arguments and use for key in list-keys, GitHub issue 5153. --- cmd-list-keys.c | 2 +- format.c | 8 ++++++++ tmux.1 | 9 +++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd-list-keys.c b/cmd-list-keys.c index 405c03c7..d8065259 100644 --- a/cmd-list-keys.c +++ b/cmd-list-keys.c @@ -35,7 +35,7 @@ "," \ "bind-key #{?key_has_repeat,#{?key_repeat,-r, },} " \ "-T #{p|#{key_table_width}:key_table} " \ - "#{p|#{key_string_width}:key_string} " \ + "#{p|#{key_string_width}:#{q|a:key_string}} " \ "#{key_command}}" static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *); diff --git a/format.c b/format.c index 75771630..7b184613 100644 --- a/format.c +++ b/format.c @@ -116,6 +116,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_NOT 0x80000 #define FORMAT_NOT_NOT 0x100000 #define FORMAT_REPEAT 0x200000 +#define FORMAT_QUOTE_ARGUMENTS 0x400000 /* Limit on recursion. */ #define FORMAT_LOOP_LIMIT 100 @@ -4164,6 +4165,11 @@ found: found = format_quote_style(saved); free(saved); } + if (modifiers & FORMAT_QUOTE_ARGUMENTS) { + saved = found; + found = args_escape(saved); + free(saved); + } return (found); } @@ -5137,6 +5143,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, else if (strchr(fm->argv[0], 'e') != NULL || strchr(fm->argv[0], 'h') != NULL) modifiers |= FORMAT_QUOTE_STYLE; + else if (strchr(fm->argv[0], 'a') != NULL) + modifiers |= FORMAT_QUOTE_ARGUMENTS; break; case 'E': modifiers |= FORMAT_EXPAND; diff --git a/tmux.1 b/tmux.1 index 9c9b38de..223580a1 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6286,12 +6286,17 @@ of the variable respectively. .Ql q:\& will escape .Xr sh 1 -special characters or with a +special characters; with a .Ql h suffix, escape hash characters (so .Ql # becomes -.Ql ## ) . +.Ql ## ) ; +or with +.Ql a +escape +.Nm +command arguments. .Ql E:\& will expand the format twice, for example .Ql #{E:status\-left}