mirror of
https://github.com/tmux/tmux.git
synced 2025-09-03 06:17:04 +00:00
Add R format modifier to repeat an argument.
This commit is contained in:
29
format.c
29
format.c
@ -106,6 +106,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
|||||||
#define FORMAT_CLIENTS 0x40000
|
#define FORMAT_CLIENTS 0x40000
|
||||||
#define FORMAT_NOT 0x80000
|
#define FORMAT_NOT 0x80000
|
||||||
#define FORMAT_NOT_NOT 0x100000
|
#define FORMAT_NOT_NOT 0x100000
|
||||||
|
#define FORMAT_REPEAT 0x200000
|
||||||
|
|
||||||
/* Limit on recursion. */
|
/* Limit on recursion. */
|
||||||
#define FORMAT_LOOP_LIMIT 100
|
#define FORMAT_LOOP_LIMIT 100
|
||||||
@ -3988,7 +3989,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Modifiers are a ; separated list of the forms:
|
* Modifiers are a ; separated list of the forms:
|
||||||
* l,m,C,a,b,c,d,n,t,w,q,E,T,S,W,P,<,>
|
* l,m,C,a,b,c,d,n,t,w,q,E,T,S,W,P,R,<,>
|
||||||
* =a
|
* =a
|
||||||
* =/a
|
* =/a
|
||||||
* =/a/
|
* =/a/
|
||||||
@ -4027,7 +4028,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now try single character with arguments. */
|
/* Now try single character with arguments. */
|
||||||
if (strchr("mCNst=peq", cp[0]) == NULL)
|
if (strchr("mCNst=pReq", cp[0]) == NULL)
|
||||||
break;
|
break;
|
||||||
c = cp[0];
|
c = cp[0];
|
||||||
|
|
||||||
@ -4582,7 +4583,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
struct format_modifier *list, *cmp = NULL, *search = NULL;
|
struct format_modifier *list, *cmp = NULL, *search = NULL;
|
||||||
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
|
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
|
||||||
struct format_modifier *bool_op_n = NULL;
|
struct format_modifier *bool_op_n = NULL;
|
||||||
u_int i, count, nsub = 0;
|
u_int i, count, nsub = 0, nrep;
|
||||||
struct format_expand_state next;
|
struct format_expand_state next;
|
||||||
|
|
||||||
/* Make a copy of the key. */
|
/* Make a copy of the key. */
|
||||||
@ -4704,6 +4705,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
case 'L':
|
case 'L':
|
||||||
modifiers |= FORMAT_CLIENTS;
|
modifiers |= FORMAT_CLIENTS;
|
||||||
break;
|
break;
|
||||||
|
case 'R':
|
||||||
|
modifiers |= FORMAT_REPEAT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (fm->size == 2) {
|
} else if (fm->size == 2) {
|
||||||
if (strcmp(fm->modifier, "||") == 0 ||
|
if (strcmp(fm->modifier, "||") == 0 ||
|
||||||
@ -4786,6 +4790,25 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
value = format_search(search, wp, new);
|
value = format_search(search, wp, new);
|
||||||
}
|
}
|
||||||
free(new);
|
free(new);
|
||||||
|
} else if (modifiers & FORMAT_REPEAT) {
|
||||||
|
/* Repeat multiple times. */
|
||||||
|
if (format_choose(es, copy, &left, &right, 1) != 0) {
|
||||||
|
format_log(es, "repeat syntax error: %s", copy);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
nrep = strtonum(right, 1, 10000, &errstr);
|
||||||
|
if (errstr != NULL)
|
||||||
|
value = xstrdup("");
|
||||||
|
else {
|
||||||
|
value = xstrdup("");
|
||||||
|
for (i = 0; i < nrep; i++) {
|
||||||
|
xasprintf(&new, "%s%s", value, left);
|
||||||
|
free(value);
|
||||||
|
value = new;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(right);
|
||||||
|
free(left);
|
||||||
} else if (modifiers & FORMAT_NOT) {
|
} else if (modifiers & FORMAT_NOT) {
|
||||||
value = format_bool_op_1(es, copy, 1);
|
value = format_bool_op_1(es, copy, 1);
|
||||||
} else if (modifiers & FORMAT_NOT_NOT) {
|
} else if (modifiers & FORMAT_NOT_NOT) {
|
||||||
|
10
tmux.1
10
tmux.1
@ -5833,6 +5833,12 @@ expands to the length of the variable and
|
|||||||
.Ql w
|
.Ql w
|
||||||
to its width when displayed, for example
|
to its width when displayed, for example
|
||||||
.Ql #{n:window_name} .
|
.Ql #{n:window_name} .
|
||||||
|
.Ql R
|
||||||
|
repeats the first argument by a number of times given by the second argument,
|
||||||
|
so
|
||||||
|
.Ql #{R:a,3}
|
||||||
|
will result in
|
||||||
|
.Ql aaa .
|
||||||
.Pp
|
.Pp
|
||||||
Prefixing a time variable with
|
Prefixing a time variable with
|
||||||
.Ql t:\&
|
.Ql t:\&
|
||||||
@ -7281,7 +7287,7 @@ Lock each client individually by running the command specified by the
|
|||||||
option.
|
option.
|
||||||
.Tg run
|
.Tg run
|
||||||
.It Xo Ic run-shell
|
.It Xo Ic run-shell
|
||||||
.Op Fl bC
|
.Op Fl bCE
|
||||||
.Op Fl c Ar start-directory
|
.Op Fl c Ar start-directory
|
||||||
.Op Fl d Ar delay
|
.Op Fl d Ar delay
|
||||||
.Op Fl t Ar target-pane
|
.Op Fl t Ar target-pane
|
||||||
@ -7309,6 +7315,8 @@ the command is run in the background.
|
|||||||
waits for
|
waits for
|
||||||
.Ar delay
|
.Ar delay
|
||||||
seconds before starting the command.
|
seconds before starting the command.
|
||||||
|
.Fl E
|
||||||
|
redirects the command's stderr to stdout instead of ignoring it.
|
||||||
If
|
If
|
||||||
.Fl c
|
.Fl c
|
||||||
is given, the current working directory is set to
|
is given, the current working directory is set to
|
||||||
|
Reference in New Issue
Block a user