dmenu-instant-20160702-3c91eed.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dmenu-instant-20160702-3c91eed.diff (2048B)
       ---
            1 diff --git a/config.def.h b/config.def.h
            2 index dcffd38..a42d28b 100644
            3 --- a/config.def.h
            4 +++ b/config.def.h
            5 @@ -1,6 +1,7 @@
            6  /* See LICENSE file for copyright and license details. */
            7  /* Default settings; can be overriden by command line. */
            8  
            9 +static int instant = 0;
           10  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
           11  /* -fn option overrides fonts[0]; default X11 font or font set */
           12  static const char *fonts[] = {
           13 diff --git a/dmenu.1 b/dmenu.1
           14 index d3ab805..8806d4d 100644
           15 --- a/dmenu.1
           16 +++ b/dmenu.1
           17 @@ -6,6 +6,7 @@ dmenu \- dynamic menu
           18  .RB [ \-b ]
           19  .RB [ \-f ]
           20  .RB [ \-i ]
           21 +.RB [ \-n ]
           22  .RB [ \-l
           23  .RB [ \-m
           24  .IR monitor ]
           25 @@ -48,6 +49,9 @@ X until stdin reaches end\-of\-file.
           26  .B \-i
           27  dmenu matches menu items case insensitively.
           28  .TP
           29 +.B \-n
           30 +dmenu instantly selects if only one match.
           31 +.TP
           32  .BI \-l " lines"
           33  dmenu lists items vertically, with the given number of lines.
           34  .TP
           35 diff --git a/dmenu.c b/dmenu.c
           36 index e0c2f80..f079479 100644
           37 --- a/dmenu.c
           38 +++ b/dmenu.c
           39 @@ -250,6 +250,13 @@ match(void)
           40                  matchend = substrend;
           41          }
           42          curr = sel = matches;
           43 +
           44 +        if(instant && matches && matches==matchend && !lsubstr) {
           45 +                puts(matches->text);
           46 +                cleanup();
           47 +                exit(0);
           48 +        }
           49 +
           50          calcoffsets();
           51  }
           52  
           53 @@ -610,7 +617,7 @@ setup(void)
           54  static void
           55  usage(void)
           56  {
           57 -        fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           58 +        fputs("usage: dmenu [-b] [-f] [-i] [-n] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
           59                "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
           60          exit(1);
           61  }
           62 @@ -632,7 +639,9 @@ main(int argc, char *argv[])
           63                  else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
           64                          fstrncmp = strncasecmp;
           65                          fstrstr = cistrstr;
           66 -                } else if (i + 1 == argc)
           67 +    } else if (!strcmp(argv[i], "-n")) /* instant select only match */
           68 +                        instant = 1;
           69 +                else if (i + 1 == argc)
           70                          usage();
           71                  /* these options take one argument */
           72                  else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */