summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2023-02-07 10:21:01 +0000
committernicm <nicm>2023-02-07 10:21:01 +0000
commit0bd78b42c0a379e46645a7083e0b4785b19e39aa (patch)
tree2eb0b3c0cc7cc6e7c214ea72fed94a9b39a02a80 /format.c
parent7acc8d703dec9f02e072ebc95495d634868b62e4 (diff)
Add an L modifier like P, W, S to loop over clients. Also fix some long
lines in tmux(1).
Diffstat (limited to 'format.c')
-rw-r--r--format.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/format.c b/format.c
index 5b08a7a4..2e1787ef 100644
--- a/format.c
+++ b/format.c
@@ -103,6 +103,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_SESSION_NAME 0x8000
#define FORMAT_CHARACTER 0x10000
#define FORMAT_COLOUR 0x20000
+#define FORMAT_CLIENTS 0x40000
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 100
@@ -3747,7 +3748,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
cp++;
/* Check single character modifiers with no arguments. */
- if (strchr("labcdnwETSWP<>", cp[0]) != NULL &&
+ if (strchr("labcdnwETSWPL<>", cp[0]) != NULL &&
format_is_end(cp[1])) {
format_add_modifier(&list, count, cp, 1, NULL, 0);
cp++;
@@ -4075,6 +4076,40 @@ format_loop_panes(struct format_expand_state *es, const char *fmt)
return (value);
}
+/* Loop over clients. */
+static char *
+format_loop_clients(struct format_expand_state *es, const char *fmt)
+{
+ struct format_tree *ft = es->ft;
+ struct client *c = ft->client;
+ struct cmdq_item *item = ft->item;
+ struct format_tree *nft;
+ struct format_expand_state next;
+ char *expanded, *value;
+ size_t valuelen;
+
+ value = xcalloc(1, 1);
+ valuelen = 1;
+
+ TAILQ_FOREACH(c, &clients, entry) {
+ format_log(es, "client loop: %s", c->name);
+ nft = format_create(c, item, 0, ft->flags);
+ format_defaults(nft, c, ft->s, ft->wl, ft->wp);
+ format_copy_state(&next, es, 0);
+ next.ft = nft;
+ expanded = format_expand1(&next, fmt);
+ format_free(nft);
+
+ valuelen += strlen(expanded);
+ value = xrealloc(value, valuelen);
+
+ strlcat(value, expanded, valuelen);
+ free(expanded);
+ }
+
+ return (value);
+}
+
static char *
format_replace_expression(struct format_modifier *mexp,
struct format_expand_state *es, const char *copy)
@@ -4349,6 +4384,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
case 'P':
modifiers |= FORMAT_PANES;
break;
+ case 'L':
+ modifiers |= FORMAT_CLIENTS;
+ break;
}
} else if (fm->size == 2) {
if (strcmp(fm->modifier, "||") == 0 ||
@@ -4405,6 +4443,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
value = format_loop_panes(es, copy);
if (value == NULL)
goto fail;
+ } else if (modifiers & FORMAT_CLIENTS) {
+ value = format_loop_clients(es, copy);
+ if (value == NULL)
+ goto fail;
} else if (modifiers & FORMAT_WINDOW_NAME) {
value = format_window_name(es, copy);
if (value == NULL)