commit 1237a6d71c6ca8d0d1f839061d4213e648f40950
Author: Tiago Teles <[email protected]>
Date:   Tue May 26 17:21:51 2020 +0100

    Page for new patch added

diff --git 
a/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-9585ad8.diff
 
b/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-9585ad8.diff
new file mode 100644
index 00000000..78a020f5
--- /dev/null
+++ 
b/tools.suckless.org/dmenu/patches/dynamicoptions/dmenu-dynamicoptions-20200526-9585ad8.diff
@@ -0,0 +1,173 @@
+From 2b7c611d792da9653e3dbb284f7624ce46bc9f65 Mon Sep 17 00:00:00 2001
+From: Tiago Teles <[email protected]>
+Date: Tue, 26 May 2020 11:56:29 +0100
+Subject: [PATCH 1/2] '-dy commandhere' option added, where said command will
+ be ran every time input changes, with the current output as the first
+ argumentand dmenu options will be changed accordingly
+
+---
+ config.def.h |  1 +
+ dmenu.c      | 38 +++++++++++++++++++++++++++++++-------
+ 2 files changed, 32 insertions(+), 7 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1edb647..035b877 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 6b8f51b..6a0eb01 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -210,9 +210,28 @@ grabkeyboard(void)
+       die("cannot grab keyboard");
+ }
+ 
++static void readstdin(FILE* stream);
++
++static void
++refreshoptions(){
++  int dynlen = strlen(dynamic);
++  char cmd[dynlen + strlen(text)];
++  strcpy(cmd, dynamic);
++  cmd[dynlen] = ' ';
++  strcpy(&cmd[dynlen] + 1, text);
++  FILE *stream = popen(cmd, "r");
++  readstdin(stream);
++  pclose(stream);
++  curr = sel = items;
++}
++
+ static void
+ match(void)
+ {
++      if(dynamic && *dynamic){
++              refreshoptions();
++      }
++
+       static char **tokv = NULL;
+       static int tokn = 0;
+ 
+@@ -234,7 +253,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 +538,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 +563,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 +703,7 @@ static void
+ usage(void)
+ {
+       fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m 
monitor]
"
+-            "             [-nb color] [-nf color] [-sb color] [-sf color] [-w 
windowid]
", stderr);
++            "             [-nb color] [-nf color] [-sb color] [-sf color] [-w 
windowid]
" "[-dy command]
", stderr);
+       exit(1);
+ }
+ 
+@@ -726,6 +746,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 +776,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
+
+
+From 9585ad8921f5fa17c9da0d613ce5fbedf98e18ef Mon Sep 17 00:00:00 2001
+From: Tiago Teles <[email protected]>
+Date: Tue, 26 May 2020 17:08:58 +0100
+Subject: [PATCH 2/2] slight modifications and errors added
+
+---
+ dmenu.c | 21 ++++++++++++---------
+ 1 file changed, 12 insertions(+), 9 deletions(-)
+
+diff --git a/dmenu.c b/dmenu.c
+index 6a0eb01..b7798e7 100644
+--- a/dmenu.c
++++ b/dmenu.c
+@@ -214,15 +214,18 @@ static void readstdin(FILE* stream);
+ 
+ static void
+ refreshoptions(){
+-  int dynlen = strlen(dynamic);
+-  char cmd[dynlen + strlen(text)];
+-  strcpy(cmd, dynamic);
+-  cmd[dynlen] = ' ';
+-  strcpy(&cmd[dynlen] + 1, text);
+-  FILE *stream = popen(cmd, "r");
+-  readstdin(stream);
+-  pclose(stream);
+-  curr = sel = items;
++      int dynlen = strlen(dynamic);
++      char* cmd= malloc(dynlen + strlen(text)+2);
++      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
+-- 
+2.26.2
+
diff --git a/tools.suckless.org/dmenu/patches/dynamicoptions/index.md 
b/tools.suckless.org/dmenu/patches/dynamicoptions/index.md
new file mode 100644
index 00000000..3de0331c
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/dynamicoptions/index.md
@@ -0,0 +1,23 @@
+dynamic options
+================
+
+Description
+-----------
+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.
+
+By default dmenu does not let you change the option list after starting it,
+this patch adds support for that.
+It is best used with the -l flag.
+
+(ie. usage: `dmenu -dy ls` runs ls on whatever directory/file you are 
currently typing
+in dmenu and lets you select it)
+
+Download
+--------
+* 
[dmenu-dynamicoptions-20200526-9585ad8.diff](dmenu-dynamicoptions-20200526-9585ad8.diff)
+
+Author
+------
+* ttmx - [email protected]


Reply via email to