[wiki] [sites] [dmenu][patch] add printindex || Jackson Abascal
commit 7529d9cdf991c3c505cb589a3878acb27f70f221
Author: Jackson Abascal <jacksonabascal_AT_gmail.com>
Date: Mon Apr 26 17:04:09 2021 -0400
[dmenu][patch] add printindex
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
new file mode 100644
index 00000000..4edd43ab
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/printindex/dmenu-printindex-5.0.diff
_AT_@ -0,0 +1,80 @@
+From e5a1ce7fca66c1d991f41df421bb7f1a4a3a8c45 Mon Sep 17 00:00:00 2001
+From: Jackson Abascal <jacksonabascal_AT_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
+_AT_@ -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
+_AT_@ -32,6 +32,7 @@ struct item {
+ char *text;
+ struct item *left, *right;
+ int out;
++ int index;
+ };
+
+ static char text[BUFSIZ] = "";
+_AT_@ -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;
+_AT_@ -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
", (sel && !(ev->state & ShiftMask)) ? sel->index : -1);
++ else
++ puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
++
+ if (!(ev->state & ControlMask)) {
+ cleanup();
+ exit(0);
+_AT_@ -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;
+_AT_@ -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
new file mode 100644
index 00000000..a63a540b
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/printindex/index.md
_AT_@ -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_AT_gmail.com>
Received on Mon Apr 26 2021 - 23:07:51 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 26 2021 - 23:12:54 CEST