commit 27a5ae855c3be3b3a405be1ec75badca16580a41
parent 39f12c7f0d14c8a9fff7c6cc912f1c387523c5bc
Author: Tiago Teles <tiago.sequeira.teles@gmail.com>
Date: Tue, 26 May 2020 20:30:48 +0100
Fixing dmenu-dynamicoptions
Hope this is the last time I have to do this.
Diffstat:
3 files changed, 135 insertions(+), 134 deletions(-)
diff --git a/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-01e2dfc7.diff b/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-01e2dfc7.diff
@@ -0,0 +1,134 @@
+From 01e2dfc79126a7600463b4cf9fa16b4be6886cae Mon Sep 17 00:00:00 2001
+From: Tiago Teles <tiago.sequeira.teles@gmail.com>
+Date: Tue, 26 May 2020 19:55:55 +0100
+Subject: [PATCH] -dy flag for dynamic menu updating
+
+This patch adds a flag (`-dy`) which makes dmenu run the command given to it
+whenever input is changed with the current input as the last argument and
+update the option list according to the output of that command.
+---
+ config.def.h | 1 +
+ dmenu.c | 43 ++++++++++++++++++++++++++++++++++++-------
+ 2 files changed, 37 insertions(+), 7 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1edb6477..035b8777 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -7,6 +7,7 @@ static const char *fonts[] = {
+ "monospace:size=10"
+ };
+ static const char *prompt = NULL; /* -p option; prompt to the left of input field */
++static const char *dynamic = NULL; /* -dy option; dynamic command to run on input change */
+ static const char *colors[SchemeLast][2] = {
+ /* fg bg */
+ [SchemeNorm] = { "#bbbbbb", "#222222" },
+diff --git a/dmenu.c b/dmenu.c
+index 6b8f51b5..356d4cc9 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -210,9 +210,33 @@ grabkeyboard(void)
+ die("cannot grab keyboard");
+ }
+
++static void readstdin(FILE* stream);
++
++static void
++refreshoptions(){
++ int dynlen = strlen(dynamic);
++ char* cmd= malloc(dynlen + strlen(text)+2);
++ if(cmd == NULL)
++ die("malloc:");
++ sprintf(cmd,"%s %s",dynamic, text);
++ FILE *stream = popen(cmd, "r");
++ if(!stream)
++ die("popen(%s):",cmd);
++ readstdin(stream);
++ int pc = pclose(stream);
++ if(pc == -1)
++ die("pclose:");
++ free(cmd);
++ curr = sel = items;
++}
++
+ static void
+ match(void)
+ {
++ if(dynamic && *dynamic){
++ refreshoptions();
++ }
++
+ static char **tokv = NULL;
+ static int tokn = 0;
+
+@@ -234,7 +258,7 @@ match(void)
+ for (i = 0; i < tokc; i++)
+ if (!fstrstr(item->text, tokv[i]))
+ break;
+- if (i != tokc) /* not all tokens match */
++ if (i != tokc && !(dynamic && *dynamic)) /* not all tokens match */
+ continue;
+ /* exact matches go first, then prefixes, then substrings */
+ if (!tokc || !fstrncmp(text, item->text, textsize))
+@@ -519,14 +543,14 @@ paste(void)
+ }
+
+ static void
+-readstdin(void)
++readstdin(FILE* stream)
+ {
+ char buf[sizeof text], *p;
+ size_t i, imax = 0, size = 0;
+ unsigned int tmpmax = 0;
+
+ /* read each line from stdin and add it to the item list */
+- for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
++ for (i = 0; fgets(buf, sizeof buf, stream); i++) {
+ if (i + 1 >= size / sizeof *items)
+ if (!(items = realloc(items, (size += BUFSIZ))))
+ die("cannot realloc %u bytes:", size);
+@@ -544,7 +568,8 @@ readstdin(void)
+ if (items)
+ items[i].text = NULL;
+ inputw = items ? TEXTW(items[imax].text) : 0;
+- lines = MIN(lines, i);
++ if (!dynamic || !*dynamic)
++ lines = MIN(lines, i);
+ }
+
+ static void
+@@ -683,7 +708,7 @@ static void
+ usage(void)
+ {
+ fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" "[-dy command]\n", stderr);
+ exit(1);
+ }
+
+@@ -726,6 +751,8 @@ main(int argc, char *argv[])
+ colors[SchemeSel][ColFg] = argv[++i];
+ else if (!strcmp(argv[i], "-w")) /* embedding window id */
+ embed = argv[++i];
++ else if (!strcmp(argv[i], "-dy")) /* dynamic command to run */
++ dynamic = argv[++i];
+ else
+ usage();
+
+@@ -754,9 +781,11 @@ main(int argc, char *argv[])
+
+ if (fast && !isatty(0)) {
+ grabkeyboard();
+- readstdin();
++ if(!(dynamic && *dynamic))
++ readstdin(stdin);
+ } else {
+- readstdin();
++ if(!(dynamic && *dynamic))
++ readstdin(stdin);
+ grabkeyboard();
+ }
+ setup();
+--
+2.26.2
+
diff --git a/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-410003e0.diff b/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-410003e0.diff
@@ -1,133 +0,0 @@
-From 410003e0d776f4038befbc3d2483a75c7e59b38f Mon Sep 17 00:00:00 2001
-From: Tiago Teles <tiago.sequeira.teles@gmail.com>
-Date: Tue, 26 May 2020 18:49:13 +0100
-Subject: [PATCH] dynamic menu updating added '-dy $command' will run `$command
- $currentinput` on input change and replace the options on dmenu with the
- output of said command.
-
----
- config.def.h | 1 +
- dmenu.c | 43 ++++++++++++++++++++++++++++++++++++-------
- 2 files changed, 37 insertions(+), 7 deletions(-)
-
-diff --git a/config.def.h b/config.def.h
-index 1edb6477..035b8777 100644
---- a/config.def.h
-+++ b/config.def.h
-@@ -7,6 +7,7 @@ static const char *fonts[] = {
- "monospace:size=10"
- };
- static const char *prompt = NULL; /* -p option; prompt to the left of input field */
-+static const char *dynamic = NULL; /* -dy option; dynamic command to run on input change */
- static const char *colors[SchemeLast][2] = {
- /* fg bg */
- [SchemeNorm] = { "#bbbbbb", "#222222" },
-diff --git a/dmenu.c b/dmenu.c
-index 6b8f51b5..2d7f2178 100644
---- a/dmenu.c
-+++ b/dmenu.c
-@@ -210,9 +210,33 @@ grabkeyboard(void)
- die("cannot grab keyboard");
- }
-
-+static void readstdin(FILE* stream);
-+
-+static void
-+refreshoptions(){
-+ int dynlen = strlen(dynamic);
-+ char* cmd= malloc(dynlen + strlen(text)+2);
-+ if(!cmd || cmd == NULL)
-+ die("malloc:");
-+ sprintf(cmd,"%s %s",dynamic, text);
-+ FILE *stream = popen(cmd, "r");
-+ if(!stream)
-+ die("popen(%s):",cmd);
-+ readstdin(stream);
-+ int pc = pclose(stream);
-+ if(pc == -1)
-+ die("pclose:");
-+ free(cmd);
-+ curr = sel = items;
-+}
-+
- static void
- match(void)
- {
-+ if(dynamic && *dynamic){
-+ refreshoptions();
-+ }
-+
- static char **tokv = NULL;
- static int tokn = 0;
-
-@@ -234,7 +258,7 @@ match(void)
- for (i = 0; i < tokc; i++)
- if (!fstrstr(item->text, tokv[i]))
- break;
-- if (i != tokc) /* not all tokens match */
-+ if (i != tokc && !(dynamic && *dynamic)) /* not all tokens match */
- continue;
- /* exact matches go first, then prefixes, then substrings */
- if (!tokc || !fstrncmp(text, item->text, textsize))
-@@ -519,14 +543,14 @@ paste(void)
- }
-
- static void
--readstdin(void)
-+readstdin(FILE* stream)
- {
- char buf[sizeof text], *p;
- size_t i, imax = 0, size = 0;
- unsigned int tmpmax = 0;
-
- /* read each line from stdin and add it to the item list */
-- for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
-+ for (i = 0; fgets(buf, sizeof buf, stream); i++) {
- if (i + 1 >= size / sizeof *items)
- if (!(items = realloc(items, (size += BUFSIZ))))
- die("cannot realloc %u bytes:", size);
-@@ -544,7 +568,8 @@ readstdin(void)
- if (items)
- items[i].text = NULL;
- inputw = items ? TEXTW(items[imax].text) : 0;
-- lines = MIN(lines, i);
-+ if (!dynamic || !*dynamic)
-+ lines = MIN(lines, i);
- }
-
- static void
-@@ -683,7 +708,7 @@ static void
- usage(void)
- {
- fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
-- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
-+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" "[-dy command]\n", stderr);
- exit(1);
- }
-
-@@ -726,6 +751,8 @@ main(int argc, char *argv[])
- colors[SchemeSel][ColFg] = argv[++i];
- else if (!strcmp(argv[i], "-w")) /* embedding window id */
- embed = argv[++i];
-+ else if (!strcmp(argv[i], "-dy")) /* dynamic command to run */
-+ dynamic = argv[++i];
- else
- usage();
-
-@@ -754,9 +781,11 @@ main(int argc, char *argv[])
-
- if (fast && !isatty(0)) {
- grabkeyboard();
-- readstdin();
-+ if(!(dynamic && *dynamic))
-+ readstdin(stdin);
- } else {
-- readstdin();
-+ if(!(dynamic && *dynamic))
-+ readstdin(stdin);
- grabkeyboard();
- }
- setup();
---
-2.26.2
-
diff --git a/tools.suckless.org/dmenu/patches/dynamicoptions/index.md b/tools.suckless.org/dmenu/patches/dynamicoptions/index.md
@@ -16,7 +16,7 @@ in dmenu and lets you select it)
Download
--------
-* [dmenu-dynamicoptions-20200526-410003e0.diff](dmenu-dynamicoptions-20200526-410003e0.diff)
+* [dmenu-dynamicoptions-20200526-01e2dfc7.diff](dmenu-dynamicoptions-20200526-01e2dfc7.diff)
Author
------