From 12b254047d5f4fe0c254a3e686a36965ff50a266 Mon Sep 17 00:00:00 2001
From: Michael Stummvoll <mich...@stummi.org>
Date: Sun, 30 Aug 2015 14:49:51 +0200
Subject: [PATCH] Introduce instant match option

with the instant match option, dmenu will close as soon as there is a
distinct match for the current input.

The default behavior will be defined in the config.def.h with the
instant option. The -n flag will toggle the default behavior.
---
 config.def.h | 2 ++
 dmenu.c      | 7 +++++++
 2 files changed, 9 insertions(+)

diff --git a/config.def.h b/config.def.h
index 4e5e3e7..22ef78b 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,6 +4,8 @@
 /* Default settings; can be overrided by command line. */
 
 static Bool topbar = True;                  /* -b  option; if False,
dmenu appears at bottom */ +static Bool instant =
False;                /* -n  option; if True, dmenu ends immediately
*/
+                                            /*             on a
distinct match               */ /* -fn option overrides fonts[0];
default X11 font or font set */ static const char *fonts[] = {
        "monospace:size=10"
diff --git a/dmenu.c b/dmenu.c
index f0bc176..a357692 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -93,6 +93,8 @@ main(int argc, char *argv[]) {
                        fstrncmp = strncasecmp;
                        fstrstr = cistrstr;
                }
+               else if(!strcmp(argv[i], "-n"))   /* instant match */
+                       instant = !instant;
                else if(i+1 == argc)
                        usage();
                /* these options take one argument */
@@ -511,6 +513,11 @@ match(void) {
                matchend = substrend;
        }
        curr = sel = matches;
+       if(instant && matches && matches==matchend && !lsubstr) {
+               puts(matches->text);
+               cleanup();
+               exit(0);
+       }
        calcoffsets();
 }
 
-- 
2.5.0


Reply via email to