1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

add prefix matching method feature (#1237)

* add prefix matching method feature

* Update helper.c

* prefix matching regex memory leak fix

* prefix matching regex memory leak fix

Co-authored-by: francis <oxfrancis@outlook.com>
This commit is contained in:
unisgn 2021-05-29 19:39:31 +08:00 committed by GitHub
parent 24dde58019
commit c3e70d4e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 17 deletions

View file

@ -410,6 +410,8 @@ Current the following methods are supported.
\fBglob\fP: match a glob pattern
.IP \(bu 2
\fBfuzzy\fP: do a fuzzy match
.IP \(bu 2
\fBprefix\fP: match prefix
.RE

View file

@ -244,6 +244,7 @@ Current the following methods are supported.
* **regex**: match a regex input
* **glob**: match a glob pattern
* **fuzzy**: do a fuzzy match
* **prefix**: match prefix
Default: *normal*

View file

@ -72,7 +72,7 @@ rofi.parse-hosts: false
rofi.parse-known-hosts: true
! "Set the modi to combine in combi mode" Set from: File
rofi.combi-modi: window,drun,run,ssh
! "Set the matching algorithm. (normal, regex, glob, fuzzy)" Set from: Default
! "Set the matching algorithm. (normal, regex, glob, fuzzy, prefix)" Set from: Default
! rofi.matching: normal
! "Tokenize input string" Set from: File
rofi.tokenize: true

View file

@ -40,7 +40,8 @@ typedef enum
MM_NORMAL = 0,
MM_REGEX = 1,
MM_GLOB = 2,
MM_FUZZY = 3
MM_FUZZY = 3,
MM_PREFIX = 4
} MatchingMethod;
/**

View file

@ -179,6 +179,14 @@ static gchar *fuzzy_to_regex ( const char * input )
return retv;
}
static gchar *prefix_regex (const char * input)
{
gchar *r = g_regex_escape_string(input, -1);
char *retv = g_strconcat("\\b", r, NULL);
g_free(r);
return retv;
}
static char *utf8_helper_simplify_string ( const char *s )
{
gunichar buf2[G_UNICHAR_MAX_DECOMPOSITION_LENGTH] = { 0, };
@ -248,6 +256,11 @@ static rofi_int_matcher * create_regex ( const char *input, int case_sensitive )
retv = R ( r, case_sensitive );
g_free ( r );
break;
case MM_PREFIX:
r = prefix_regex(input);
retv = R(r, case_sensitive);
g_free(r);
break;
default:
r = g_regex_escape_string ( input, -1 );
retv = R ( r, case_sensitive );
@ -632,8 +645,11 @@ int config_sanity_check ( void )
else if ( g_strcmp0 ( config.matching, "normal" ) == 0 ) {
config.matching_method = MM_NORMAL;;
}
else if (g_strcmp0 (config.matching, "prefix") == 0) {
config.matching_method = MM_PREFIX;
}
else {
g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy or normal.\n",
g_string_append_printf ( msg, "\t<b>config.matching</b>=%s is not a valid matching strategy.\nValid options are: glob, regex, fuzzy, prefix or normal.\n",
config.matching );
found_error = 1;
}

View file

@ -169,7 +169,7 @@ static XrmOption xrmOptions[] = {
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL,
"Set the modi to combine in combi mode", CONFIG_DEFAULT },
{ xrm_String, "matching", { .str = &config.matching }, NULL,
"Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT },
"Set the matching algorithm. (normal, regex, glob, fuzzy, prefix)", CONFIG_DEFAULT },
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL,
"Tokenize input string", CONFIG_DEFAULT },
{ xrm_String, "monitor", { .str = &config.monitor }, NULL,