mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-11 13:50:48 -05:00
Add tokenize option and append * to glob.
This commit is contained in:
parent
1369c162fe
commit
6b039ac524
5 changed files with 30 additions and 7 deletions
|
@ -129,8 +129,9 @@ Settings config = {
|
||||||
/** Modi to combine into one view. */
|
/** Modi to combine into one view. */
|
||||||
.combi_modi = "window,run",
|
.combi_modi = "window,run",
|
||||||
/** Fuzzy matching. */
|
/** Fuzzy matching. */
|
||||||
.fuzzy = FALSE,
|
.fuzzy = FALSE,
|
||||||
.glob = FALSE,
|
.glob = FALSE,
|
||||||
|
.tokenize = FALSE,
|
||||||
/** Monitor */
|
/** Monitor */
|
||||||
.monitor = -1,
|
.monitor = -1,
|
||||||
/** set line margin */
|
/** set line margin */
|
||||||
|
|
|
@ -231,6 +231,7 @@ typedef struct _Settings
|
||||||
/** Fuzzy match */
|
/** Fuzzy match */
|
||||||
unsigned int fuzzy;
|
unsigned int fuzzy;
|
||||||
unsigned int glob;
|
unsigned int glob;
|
||||||
|
unsigned int tokenize;
|
||||||
/** Monitors */
|
/** Monitors */
|
||||||
int monitor;
|
int monitor;
|
||||||
/** Line margin */
|
/** Line margin */
|
||||||
|
|
|
@ -59,8 +59,8 @@ typedef struct _DmenuModePrivateData
|
||||||
|
|
||||||
static char **get_dmenu ( unsigned int *length )
|
static char **get_dmenu ( unsigned int *length )
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
|
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,21 @@ char **tokenize ( const char *input, int case_sensitive )
|
||||||
|
|
||||||
char *saveptr = NULL, *token;
|
char *saveptr = NULL, *token;
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
|
if ( !config.tokenize ) {
|
||||||
|
retv = g_malloc0 ( sizeof ( char* ) * 2 );
|
||||||
|
if ( config.glob ) {
|
||||||
|
token = g_strconcat ( input, "*", NULL );
|
||||||
|
retv[0] = token_collate_key ( token, case_sensitive );
|
||||||
|
g_free ( token ); token = NULL;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
token = token_collate_key ( input, case_sensitive );
|
||||||
|
}
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
// First entry is always full (modified) stringtext.
|
// First entry is always full (modified) stringtext.
|
||||||
int num_tokens = 0;
|
int num_tokens = 0;
|
||||||
|
|
||||||
// Copy the string, 'strtok_r' modifies it.
|
// Copy the string, 'strtok_r' modifies it.
|
||||||
char *str = g_strdup ( input );
|
char *str = g_strdup ( input );
|
||||||
|
@ -185,8 +198,15 @@ char **tokenize ( const char *input, int case_sensitive )
|
||||||
// Iterate over tokens.
|
// Iterate over tokens.
|
||||||
// strtok should still be valid for utf8.
|
// strtok should still be valid for utf8.
|
||||||
for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) {
|
for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) {
|
||||||
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
|
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
|
||||||
retv[num_tokens] = token_collate_key ( token, case_sensitive );
|
if ( config.glob ) {
|
||||||
|
char *t = token_collate_key ( token, case_sensitive );
|
||||||
|
retv[num_tokens] = g_strconcat ( t, "*", NULL );
|
||||||
|
g_free ( t );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
retv[num_tokens] = token_collate_key ( token, case_sensitive );
|
||||||
|
}
|
||||||
retv[num_tokens + 1] = NULL;
|
retv[num_tokens + 1] = NULL;
|
||||||
num_tokens++;
|
num_tokens++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,7 @@ static XrmOption xrmOptions[] = {
|
||||||
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
|
{ xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL },
|
||||||
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL },
|
{ xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL },
|
||||||
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL },
|
{ xrm_Boolean, "glob", { .num = &config.glob }, NULL },
|
||||||
|
{ xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL },
|
||||||
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL },
|
{ xrm_Number, "monitor", { .snum = &config.monitor }, NULL },
|
||||||
/* Alias for dmenu compatibility. */
|
/* Alias for dmenu compatibility. */
|
||||||
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL },
|
{ xrm_SNumber, "m", { .snum = &config.monitor }, NULL },
|
||||||
|
|
Loading…
Reference in a new issue