sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dmenu-instant-4.7.diff (2041B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 1edb647..37f43d5 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 9eab758..98d3725 100644
     15 --- a/dmenu.1
     16 +++ b/dmenu.1
     17 @@ -3,7 +3,7 @@
     18  dmenu \- dynamic menu
     19  .SH SYNOPSIS
     20  .B dmenu
     21 -.RB [ \-bfiv ]
     22 +.RB [ \-bfinv ]
     23  .RB [ \-l
     24  .IR lines ]
     25  .RB [ \-m
     26 @@ -47,6 +47,9 @@ X until stdin reaches end\-of\-file.
     27  .B \-i
     28  dmenu matches menu items case insensitively.
     29  .TP
     30 +.B \-n
     31 +dmenu instantly selects if only one match.
     32 +.TP
     33  .BI \-l " lines"
     34  dmenu lists items vertically, with the given number of lines.
     35  .TP
     36 diff --git a/dmenu.c b/dmenu.c
     37 index d605ab4..2c2f03e 100644
     38 --- a/dmenu.c
     39 +++ b/dmenu.c
     40 @@ -260,6 +260,13 @@ match(void)
     41  		matchend = substrend;
     42  	}
     43  	curr = sel = matches;
     44 +
     45 +	if(instant && matches && matches==matchend && !lsubstr) {
     46 +		puts(matches->text);
     47 +		cleanup();
     48 +		exit(0);
     49 +	}
     50 +
     51  	calcoffsets();
     52  }
     53  
     54 @@ -636,7 +643,7 @@ setup(void)
     55  static void
     56  usage(void)
     57  {
     58 -	fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     59 +	fputs("usage: dmenu [-bfinv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     60  	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
     61  	exit(1);
     62  }
     63 @@ -659,7 +666,9 @@ main(int argc, char *argv[])
     64  		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
     65  			fstrncmp = strncasecmp;
     66  			fstrstr = cistrstr;
     67 -		} else if (i + 1 == argc)
     68 +		} else if (!strcmp(argv[i], "-n")) /* instant select only match */
     69 +			instant = 1;
     70 +		else if (i + 1 == argc)
     71  			usage();
     72  		/* these options take one argument */
     73  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */