mirror of
https://github.com/tmux/tmux.git
synced 2025-01-07 16:28:48 +00:00
Add <, >, <=, >= for formats, GitHub issue 1747.
This commit is contained in:
parent
207789dc2d
commit
a65a6d62d1
39
format.c
39
format.c
@ -1136,13 +1136,13 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Modifiers are a ; separated list of the forms:
|
* Modifiers are a ; separated list of the forms:
|
||||||
* l,m,C,b,d,t,q,E,T,S,W,P
|
* l,m,C,b,d,t,q,E,T,S,W,P,<,>
|
||||||
* =a
|
* =a
|
||||||
* =/a
|
* =/a
|
||||||
* =/a/
|
* =/a/
|
||||||
* s/a/b/
|
* s/a/b/
|
||||||
* s/a/b
|
* s/a/b
|
||||||
* ||,&&,!=,==
|
* ||,&&,!=,==,<=,>=
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*count = 0;
|
*count = 0;
|
||||||
@ -1153,7 +1153,7 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count)
|
|||||||
cp++;
|
cp++;
|
||||||
|
|
||||||
/* Check single character modifiers with no arguments. */
|
/* Check single character modifiers with no arguments. */
|
||||||
if (strchr("lmCbdtqETSWP", cp[0]) != NULL &&
|
if (strchr("lmCbdtqETSWP<>", cp[0]) != NULL &&
|
||||||
format_is_end(cp[1])) {
|
format_is_end(cp[1])) {
|
||||||
format_add_modifier(&list, count, cp, 1, NULL, 0);
|
format_add_modifier(&list, count, cp, 1, NULL, 0);
|
||||||
cp++;
|
cp++;
|
||||||
@ -1164,7 +1164,9 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count)
|
|||||||
if ((memcmp("||", cp, 2) == 0 ||
|
if ((memcmp("||", cp, 2) == 0 ||
|
||||||
memcmp("&&", cp, 2) == 0 ||
|
memcmp("&&", cp, 2) == 0 ||
|
||||||
memcmp("!=", cp, 2) == 0 ||
|
memcmp("!=", cp, 2) == 0 ||
|
||||||
memcmp("==", cp, 2) == 0) &&
|
memcmp("==", cp, 2) == 0 ||
|
||||||
|
memcmp("<=", cp, 2) == 0 ||
|
||||||
|
memcmp(">=", cp, 2) == 0) &&
|
||||||
format_is_end(cp[2])) {
|
format_is_end(cp[2])) {
|
||||||
format_add_modifier(&list, count, cp, 2, NULL, 0);
|
format_add_modifier(&list, count, cp, 2, NULL, 0);
|
||||||
cp += 2;
|
cp += 2;
|
||||||
@ -1433,6 +1435,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
if (fm->size == 1) {
|
if (fm->size == 1) {
|
||||||
switch (fm->modifier[0]) {
|
switch (fm->modifier[0]) {
|
||||||
case 'm':
|
case 'm':
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
cmp = fm;
|
cmp = fm;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
@ -1486,7 +1490,9 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
if (strcmp(fm->modifier, "||") == 0 ||
|
if (strcmp(fm->modifier, "||") == 0 ||
|
||||||
strcmp(fm->modifier, "&&") == 0 ||
|
strcmp(fm->modifier, "&&") == 0 ||
|
||||||
strcmp(fm->modifier, "==") == 0 ||
|
strcmp(fm->modifier, "==") == 0 ||
|
||||||
strcmp(fm->modifier, "!=") == 0)
|
strcmp(fm->modifier, "!=") == 0 ||
|
||||||
|
strcmp(fm->modifier, ">=") == 0 ||
|
||||||
|
strcmp(fm->modifier, "<=") == 0)
|
||||||
cmp = fm;
|
cmp = fm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1549,8 +1555,27 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
|||||||
value = xstrdup("1");
|
value = xstrdup("1");
|
||||||
else
|
else
|
||||||
value = xstrdup("0");
|
value = xstrdup("0");
|
||||||
}
|
} else if (strcmp(cmp->modifier, "<") == 0) {
|
||||||
else if (strcmp(cmp->modifier, "m") == 0) {
|
if (strcmp(left, right) < 0)
|
||||||
|
value = xstrdup("1");
|
||||||
|
else
|
||||||
|
value = xstrdup("0");
|
||||||
|
} else if (strcmp(cmp->modifier, ">") == 0) {
|
||||||
|
if (strcmp(left, right) > 0)
|
||||||
|
value = xstrdup("1");
|
||||||
|
else
|
||||||
|
value = xstrdup("0");
|
||||||
|
} else if (strcmp(cmp->modifier, "<=") == 0) {
|
||||||
|
if (strcmp(left, right) <= 0)
|
||||||
|
value = xstrdup("1");
|
||||||
|
else
|
||||||
|
value = xstrdup("0");
|
||||||
|
} else if (strcmp(cmp->modifier, ">=") == 0) {
|
||||||
|
if (strcmp(left, right) >= 0)
|
||||||
|
value = xstrdup("1");
|
||||||
|
else
|
||||||
|
value = xstrdup("0");
|
||||||
|
} else if (strcmp(cmp->modifier, "m") == 0) {
|
||||||
if (fnmatch(left, right, 0) == 0)
|
if (fnmatch(left, right, 0) == 0)
|
||||||
value = xstrdup("1");
|
value = xstrdup("1");
|
||||||
else
|
else
|
||||||
|
8
tmux.1
8
tmux.1
@ -3946,9 +3946,13 @@ For example:
|
|||||||
.Pp
|
.Pp
|
||||||
Comparisons may be expressed by prefixing two comma-separated
|
Comparisons may be expressed by prefixing two comma-separated
|
||||||
alternatives by
|
alternatives by
|
||||||
.Ql ==
|
.Ql == ,
|
||||||
|
.Ql != ,
|
||||||
|
.Ql < ,
|
||||||
|
.Ql > ,
|
||||||
|
.Ql <=
|
||||||
or
|
or
|
||||||
.Ql !=
|
.Ql >=
|
||||||
and a colon.
|
and a colon.
|
||||||
For example
|
For example
|
||||||
.Ql #{==:#{host},myhost}
|
.Ql #{==:#{host},myhost}
|
||||||
|
Loading…
Reference in New Issue
Block a user