sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 7529d9cdf991c3c505cb589a3878acb27f70f221
parent 5754009143ed91d7db464ef8255df210a84d0c51
Author: Jackson Abascal <jacksonabascal@gmail.com>
Date:   Mon, 26 Apr 2021 17:04:09 -0400

[dmenu][patch] add printindex

Diffstat:
Atools.suckless.org/dmenu/patches/printindex/dmenu-printindex-5.0.diff | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/printindex/index.md | 13+++++++++++++
2 files changed, 93 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/printindex/dmenu-printindex-5.0.diff b/tools.suckless.org/dmenu/patches/printindex/dmenu-printindex-5.0.diff @@ -0,0 +1,80 @@ +From e5a1ce7fca66c1d991f41df421bb7f1a4a3a8c45 Mon Sep 17 00:00:00 2001 +From: Jackson Abascal <jacksonabascal@gmail.com> +Date: Mon, 26 Apr 2021 15:39:29 -0400 +Subject: [PATCH] gives dmenu the ability to print the index of matched text + instead of the text itself + +--- + dmenu.1 | 3 +++ + dmenu.c | 13 +++++++++++-- + 2 files changed, 14 insertions(+), 2 deletions(-) + +diff --git a/dmenu.1 b/dmenu.1 +index 323f93c..b3c5f13 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file. + .B \-i + dmenu matches menu items case insensitively. + .TP ++.B \-ix ++dmenu prints the index of matched text instead of the text itself. ++.TP + .BI \-l " lines" + dmenu lists items vertically, with the given number of lines. + .TP +diff --git a/dmenu.c b/dmenu.c +index 65f25ce..172a2b4 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -32,6 +32,7 @@ struct item { + char *text; + struct item *left, *right; + int out; ++ int index; + }; + + static char text[BUFSIZ] = ""; +@@ -44,6 +45,7 @@ static struct item *items = NULL; + static struct item *matches, *matchend; + static struct item *prev, *curr, *next, *sel; + static int mon = -1, screen; ++static int print_index = 0; + + static Atom clip, utf8; + static Display *dpy; +@@ -464,7 +466,11 @@ insert: + break; + case XK_Return: + case XK_KP_Enter: +- puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); ++ if (print_index) ++ printf("%d\n", (sel && !(ev->state & ShiftMask)) ? sel->index : -1); ++ else ++ puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); ++ + if (!(ev->state & ControlMask)) { + cleanup(); + exit(0); +@@ -535,6 +541,7 @@ readstdin(void) + if (!(items[i].text = strdup(buf))) + die("cannot strdup %u bytes:", strlen(buf) + 1); + items[i].out = 0; ++ items[i].index = i; + drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL); + if (tmpmax > inputw) { + inputw = tmpmax; +@@ -712,7 +719,9 @@ main(int argc, char *argv[]) + else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ + fstrncmp = strncasecmp; + fstrstr = cistrstr; +- } else if (i + 1 == argc) ++ } else if (!strcmp(argv[i], "-ix")) /* adds ability to return index in list */ ++ print_index = 1; ++ else if (i + 1 == argc) + usage(); + /* these options take one argument */ + else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ +-- +2.31.1 + diff --git a/tools.suckless.org/dmenu/patches/printindex/index.md b/tools.suckless.org/dmenu/patches/printindex/index.md @@ -0,0 +1,13 @@ +Print Index +================== +This patch allows dmenu to print out the 0-based index of matched text instead of the matched text itself. This is useful in cases where you would like to select entries from one array of text but index into another, or when you are selecting from an ordered list of non-unique items. + +Pass the _-ix_ flag to dmenu to enable index printing. + +Download +-------- +* [dmenu-printindex-5.0.diff](dmenu-printindex-5.0.diff) + +Author +------- +* Jackson Abascal - <jacksonabascal@gmail.com>