Add E: format to expand a format twice (useful to expand the value of an

option).
pull/1633/head
nicm 2019-03-13 14:19:54 +00:00
parent 71e00c718c
commit 9032ac2a05
2 changed files with 18 additions and 1 deletions

View File

@ -94,6 +94,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_DIRNAME 0x4
#define FORMAT_QUOTE 0x8
#define FORMAT_LITERAL 0x10
#define FORMAT_EXPAND 0x20
/* Entry in format tree. */
struct format_entry {
@ -1012,7 +1013,7 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count)
cp++;
/* Check single character modifiers with no arguments. */
if (strchr("lmCbdtq", cp[0]) != NULL && format_is_end(cp[1])) {
if (strchr("lmCbdtqE", cp[0]) != NULL && format_is_end(cp[1])) {
format_add_modifier(&list, count, cp, 1, NULL, 0);
cp++;
continue;
@ -1189,6 +1190,9 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
case 'q':
modifiers |= FORMAT_QUOTE;
break;
case 'E':
modifiers |= FORMAT_EXPAND;
break;
}
} else if (fm->size == 2) {
if (strcmp(fm->modifier, "||") == 0 ||
@ -1289,6 +1293,13 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
value = xstrdup("");
}
/* Expand again if required. */
if (modifiers & FORMAT_EXPAND) {
new = format_expand(ft, value);
free(value);
value = new;
}
/* Perform substitution if any. */
if (sub != NULL) {
new = format_substitute(value, sub->argv[0], sub->argv[1]);

6
tmux.1
View File

@ -3713,6 +3713,12 @@ of the variable respectively.
will escape
.Xr sh 1
special characters.
.Ql E:
will expand the format twice, for example
.Ql #{E:status-left}
is the result of expanding the content of the
.Ic status-left
option rather than the content itself.
A prefix of the form
.Ql s/foo/bar/:
will substitute