dmenu-instant-5.3.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dmenu-instant-5.3.diff (2522B)
       ---
            1 From 26b302783a16dc2aa19451d9ba4515c8484f4a05 Mon Sep 17 00:00:00 2001
            2 From: Max Schillinger <maxschillinger@web.de>
            3 Date: Tue, 27 Aug 2024 16:19:41 +0200
            4 Subject: [PATCH] Instant mode
            5 
            6 Add '-n' flag to select the only (remaining) entry automatically.
            7 ---
            8  config.def.h |  1 +
            9  dmenu.1      |  5 ++++-
           10  dmenu.c      | 13 +++++++++++--
           11  3 files changed, 16 insertions(+), 3 deletions(-)
           12 
           13 diff --git a/config.def.h b/config.def.h
           14 index 1edb647..7e6f1ed 100644
           15 --- a/config.def.h
           16 +++ b/config.def.h
           17 @@ -1,6 +1,7 @@
           18  /* See LICENSE file for copyright and license details. */
           19  /* Default settings; can be overriden by command line. */
           20  
           21 +static int instant = 0;                     /* -n  option; if 1, select single entry automatically */
           22  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
           23  /* -fn option overrides fonts[0]; default X11 font or font set */
           24  static const char *fonts[] = {
           25 diff --git a/dmenu.1 b/dmenu.1
           26 index 323f93c..29bdf7f 100644
           27 --- a/dmenu.1
           28 +++ b/dmenu.1
           29 @@ -3,7 +3,7 @@
           30  dmenu \- dynamic menu
           31  .SH SYNOPSIS
           32  .B dmenu
           33 -.RB [ \-bfiv ]
           34 +.RB [ \-bfinv ]
           35  .RB [ \-l
           36  .IR lines ]
           37  .RB [ \-m
           38 @@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
           39  .B \-i
           40  dmenu matches menu items case insensitively.
           41  .TP
           42 +.B \-n
           43 +dmenu instantly selects if only one match.
           44 +.TP
           45  .BI \-l " lines"
           46  dmenu lists items vertically, with the given number of lines.
           47  .TP
           48 diff --git a/dmenu.c b/dmenu.c
           49 index 40f93e0..92d5154 100644
           50 --- a/dmenu.c
           51 +++ b/dmenu.c
           52 @@ -277,6 +277,13 @@ match(void)
           53                  matchend = substrend;
           54          }
           55          curr = sel = matches;
           56 +
           57 +        if (instant && matches && matches==matchend && !lsubstr) {
           58 +                puts(matches->text);
           59 +                cleanup();
           60 +                exit(0);
           61 +        }
           62 +
           63          calcoffsets();
           64  }
           65  
           66 @@ -715,7 +722,7 @@ setup(void)
           67  static void
           68  usage(void)
           69  {
           70 -        die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           71 +        die("usage: dmenu [-bfinv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           72              "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
           73  }
           74  
           75 @@ -737,7 +744,9 @@ main(int argc, char *argv[])
           76                  else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
           77                          fstrncmp = strncasecmp;
           78                          fstrstr = cistrstr;
           79 -                } else if (i + 1 == argc)
           80 +                } else if (!strcmp(argv[i], "-n")) /* instant select only match */
           81 +                        instant = 1;
           82 +                else if (i + 1 == argc)
           83                          usage();
           84                  /* these options take one argument */
           85                  else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
           86 -- 
           87 2.46.0
           88