mirror of
https://github.com/tmux/tmux.git
synced 2026-06-24 08:57:18 +00:00
Add z modifier to m operator for fuzzy match.
This commit is contained in:
24
format.c
24
format.c
@@ -4507,6 +4507,25 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
return (list);
|
||||
}
|
||||
|
||||
/* Fuzzy match strings. */
|
||||
static int
|
||||
format_fuzzy_match(const char *pattern, const char *text, int icase)
|
||||
{
|
||||
while (*pattern != '\0') {
|
||||
if (*text == '\0')
|
||||
return (0);
|
||||
if (icase) {
|
||||
if (tolower((u_char)*pattern) == tolower((u_char)*text))
|
||||
pattern++;
|
||||
} else {
|
||||
if (*pattern == *text)
|
||||
pattern++;
|
||||
}
|
||||
text++;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Match against an fnmatch(3) pattern or regular expression. */
|
||||
static char *
|
||||
format_match(struct format_modifier *fm, const char *pattern, const char *text)
|
||||
@@ -4517,7 +4536,10 @@ format_match(struct format_modifier *fm, const char *pattern, const char *text)
|
||||
|
||||
if (fm->argc >= 1)
|
||||
s = fm->argv[0];
|
||||
if (strchr(s, 'r') == NULL) {
|
||||
if (strchr(s, 'z') != NULL) {
|
||||
if (!format_fuzzy_match(pattern, text, strchr(s, 'i') != NULL))
|
||||
return (xstrdup("0"));
|
||||
} else if (strchr(s, 'r') == NULL) {
|
||||
if (strchr(s, 'i') != NULL)
|
||||
flags |= FNM_CASEFOLD;
|
||||
if (fnmatch(pattern, text, flags) != 0)
|
||||
|
||||
10
tmux.1
10
tmux.1
@@ -6379,13 +6379,19 @@ An optional argument specifies flags:
|
||||
.Ql r
|
||||
means the pattern is a regular expression instead of the default
|
||||
.Xr glob 7
|
||||
pattern, and
|
||||
pattern,
|
||||
.Ql z
|
||||
means the pattern is a fuzzy match, that is, it matches if its characters
|
||||
appear in the string in order but not necessarily consecutively,
|
||||
and
|
||||
.Ql i
|
||||
means to ignore case.
|
||||
For example:
|
||||
.Ql #{m:*foo*,#{host}}
|
||||
or
|
||||
.Ql #{m/ri:\[ha]A,MYVAR} .
|
||||
.Ql #{m/ri:\[ha]A,MYVAR}
|
||||
or
|
||||
.Ql #{m/z:abc,aXbXc} .
|
||||
A
|
||||
.Ql C
|
||||
performs a search for a
|
||||
|
||||
Reference in New Issue
Block a user