diff --git a/docs/docs.md b/docs/docs.md index a9c786e..d3e2c66 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -41,6 +41,8 @@ On top of this, you can specify arguments to change the behavior of spmenu. See - spmenu -nmt text - Set normal mode text to text - spmenu -imt text - Set insert mode text to text - spmenu -bw - Width of the border. 0 will disable the border +- spmenu -so - Sort matches +- spmenu -nso - Don't sort matches - spmenu -s - Use case-sensitive matching - spmenu -i - Use case-insensitive matching - spmenu -nm - Start spmenu in normal mode @@ -124,6 +126,7 @@ On top of this, you can specify arguments to change the behavior of spmenu. See There are also extra arguments recognized for dmenu compatibility. These are: +- spmenu -S - Don't sort matches - spmenu -nb color - Set the normal background color - spmenu -nf color - Set the normal foreground color - spmenu -sb color - Set the selected background color diff --git a/libs/argv.c b/libs/argv.c index 6347fad..f96399c 100644 --- a/libs/argv.c +++ b/libs/argv.c @@ -60,6 +60,12 @@ readargs(int argc, char *argv[]) else if (!strcmp(argv[i], "-s")) { /* case-sensitive item matching */ fstrncmp = strncmp; fstrstr = strstr; + } else if (!strcmp(argv[i], "-S")) { /* don't sort */ + sortmatches = 0; + } else if (!strcmp(argv[i], "-nso")) { /* don't sort */ + sortmatches = 0; + } else if (!strcmp(argv[i], "-so")) { /* don't sort */ + sortmatches = 1; } else if (!strcmp(argv[i], "-i")) { /* case-sensitive item matching, for compatibility reasons */ fstrncmp = strncasecmp; fstrstr = cistrstr; @@ -293,6 +299,8 @@ usage(void) "spmenu -nmt Set normal mode text to \n" "spmenu -imt Set insert mode text to \n" "spmenu -bw Width of the border. 0 will disable the border\n" + "spmenu -so Sort matches\n" + "spmenu -nso Don't sort matches\n" "spmenu -s Use case-sensitive matching\n" "spmenu -i Use case-insensitive matching\n" "spmenu -nm Start spmenu in normal mode\n" @@ -378,6 +386,7 @@ usage(void) "spmenu -sgr15 Set the SGR 15 color\n" "\n", stdout); fputs("- dmenu compatibility -\n" + "spmenu -S Don't sort matches\n" "spmenu -nb Set the normal background color\n" "spmenu -nf Set the normal foreground color\n" "spmenu -sb Set the selected background color\n" diff --git a/options.h b/options.h index e47e8f0..d065d00 100644 --- a/options.h +++ b/options.h @@ -42,6 +42,7 @@ static char *password = "."; /* Password character, when the -P /* Match options */ static int type = 1; /* Allow typing into spmenu or only allow keybinds. */ +static int sortmatches = 1; /* Sort matches (0/1) */ static int casesensitive = 0; /* Case-sensitive by default? (0/1) */ static int preselected = 0; /* Which line should spmenu preselect? */ static int accuratewidth = 1; /* Enable accurate width. May have a performance hit if you are matching a lot of items at once */ diff --git a/spmenu.1 b/spmenu.1 index dd2a33d..4ae5fb1 100644 --- a/spmenu.1 +++ b/spmenu.1 @@ -94,6 +94,10 @@ spmenu -imt text - Set insert mode text to text spmenu -bw - Width of the border. 0 will disable the border .IP \[bu] 2 +spmenu -so - Sort matches +.IP \[bu] 2 +spmenu -nso - Don\[cq]t sort matches +.IP \[bu] 2 spmenu -s - Use case-sensitive matching .IP \[bu] 2 spmenu -i - Use case-insensitive matching @@ -256,6 +260,8 @@ spmenu -sgr15 - Set the SGR 15 color There are also extra arguments recognized for dmenu compatibility. These are: .IP \[bu] 2 +spmenu -S - Don\[cq]t sort matches +.IP \[bu] 2 spmenu -nb color - Set the normal background color .IP \[bu] 2 spmenu -nf color - Set the normal foreground color diff --git a/spmenu.c b/spmenu.c index 37fa871..19e000b 100644 --- a/spmenu.c +++ b/spmenu.c @@ -603,13 +603,17 @@ match(void) break; if (i != tokc) /* not all tokens match */ continue; - /* exact matches go first, then prefixes, then substrings */ - if (!tokc || !fstrncmp(text, item->text, textsize)) + if (!sortmatches) appenditem(item, &matches, &matchend); - else if (!fstrncmp(tokv[0], item->text, len)) - appenditem(item, &lprefix, &prefixend); - else - appenditem(item, &lsubstr, &substrend); + else { + /* exact matches go first, then prefixes, then substrings */ + if (!tokc || !fstrncmp(text, item->text, textsize)) + appenditem(item, &matches, &matchend); + else if (!fstrncmp(tokv[0], item->text, len)) + appenditem(item, &lprefix, &prefixend); + else + appenditem(item, &lsubstr, &substrend); + } } if (lprefix) { if (matches) {