Extend match to do multiple terms.

This commit is contained in:
nicm
2026-06-23 08:35:28 +00:00
parent b82048eb18
commit 748ef8b2ae
2 changed files with 33 additions and 4 deletions

View File

@@ -4507,11 +4507,14 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
return (list);
}
/* Fuzzy match strings. */
/* Fuzzy match a single token (no spaces). */
static int
format_fuzzy_match(const char *pattern, const char *text, int icase)
format_fuzzy_match_token(const char *pattern, size_t patternlen,
const char *text, int icase)
{
while (*pattern != '\0') {
const char *end = pattern + patternlen;
while (pattern != end) {
if (*text == '\0')
return (0);
if (icase) {
@@ -4526,6 +4529,31 @@ format_fuzzy_match(const char *pattern, const char *text, int icase)
return (1);
}
/*
* Fuzzy match strings. The pattern is split on spaces into tokens and every
* token must match as a sequence.
*/
static int
format_fuzzy_match(const char *pattern, const char *text, int icase)
{
const char *start;
size_t len;
while (*pattern != '\0') {
while (*pattern == ' ')
pattern++;
if (*pattern == '\0')
break;
start = pattern;
while (*pattern != '\0' && *pattern != ' ')
pattern++;
len = pattern - start;
if (!format_fuzzy_match_token(start, len, text, icase))
return (0);
}
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)

3
tmux.1
View File

@@ -6385,7 +6385,8 @@ means the pattern is a regular expression instead of the default
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,
appear in the string in order but not necessarily consecutively;
the pattern is split on spaces into separate terms which must all match,
and
.Ql i
means to ignore case.