dmenu-instant-4.6.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dmenu-instant-4.6.diff (2097B)
---
1 From e95c945f9a6afe486782962dfe2dd81c00c05781 Mon Sep 17 00:00:00 2001
2 From: Hiltjo Posthuma <hiltjo@codemadness.org>
3 Date: Fri, 17 Jun 2016 13:24:21 +0200
4 Subject: [PATCH] dmenu instant match: end dmenu immediately if there is one
5 match left.
6
7 ---
8 config.def.h | 1 +
9 dmenu.1 | 4 ++++
10 dmenu.c | 7 +++++++
11 3 files changed, 12 insertions(+)
12
13 diff --git a/config.def.h b/config.def.h
14 index dcffd38..b06f1d5 100644
15 --- a/config.def.h
16 +++ b/config.def.h
17 @@ -2,6 +2,7 @@
18 /* Default settings; can be overriden by command line. */
19
20 static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
21 +static int instant = 0; /* -n option; if 1, dmenu ends immediately on a distinct match */
22 /* -fn option overrides fonts[0]; default X11 font or font set */
23 static const char *fonts[] = {
24 "monospace:size=10"
25 diff --git a/dmenu.1 b/dmenu.1
26 index d3ab805..f0aa123 100644
27 --- a/dmenu.1
28 +++ b/dmenu.1
29 @@ -10,6 +10,7 @@ dmenu \- dynamic menu
30 .RB [ \-m
31 .IR monitor ]
32 .IR lines ]
33 +.RB [ \-n ]
34 .RB [ \-p
35 .IR prompt ]
36 .RB [ \-fn
37 @@ -55,6 +56,9 @@ dmenu lists items vertically, with the given number of lines.
38 dmenu is displayed on the monitor number supplied. Monitor numbers are starting
39 from 0.
40 .TP
41 +.BI \-n
42 +instant match, end dmenu if there is only one match left.
43 +.TP
44 .BI \-p " prompt"
45 defines the prompt to be displayed to the left of the input field.
46 .TP
47 diff --git a/dmenu.c b/dmenu.c
48 index e0c2f80..0c41d46 100644
49 --- a/dmenu.c
50 +++ b/dmenu.c
51 @@ -250,6 +250,11 @@ match(void)
52 matchend = substrend;
53 }
54 curr = sel = matches;
55 + if (instant && matches && matches == matchend && !lsubstr) {
56 + puts(matches->text);
57 + cleanup();
58 + exit(0);
59 + }
60 calcoffsets();
61 }
62
63 @@ -632,6 +637,8 @@ 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 (!strcmp(argv[i], "-n")) { /* instant match */
68 + instant = !instant;
69 } else if (i + 1 == argc)
70 usage();
71 /* these options take one argument */
72 --
73 2.8.3
74