dmenu

My dmenu build
git clone https://git.regexghost.com/dmenu.git
Log | Files | Refs | README | LICENSE

commit 372a9fda9af1abffff231065ab3f9f755dd77b12
parent b36a036b83a632ceb6aeb10b66326caf04542e9a
Author: regexghost <regexghost@protonmail.com>
Date:   Thu, 23 Apr 2026 08:56:32 +0100

print index patch

Diffstat:
Mdmenu.1 | 3+++
Mdmenu.c | 13+++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/dmenu.1 b/dmenu.1 @@ -65,6 +65,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 @@ -35,6 +35,7 @@ struct item { unsigned int width; struct item *left, *right; int out; + int index; double distance; }; @@ -48,6 +49,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; @@ -627,7 +629,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); @@ -704,6 +710,7 @@ readstdin(void) items[i].width = TEXTW(line); items[i].out = 0; + items[i].index = i; } free(line); if (items) @@ -897,7 +904,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 */