--- a/dmenu.1	2010-12-28 17:26:44.368974910 +0000
+++ b/dmenu.1	2010-12-28 17:28:41.902912662 +0000
@@ -5,6 +5,7 @@ dmenu \- dynamic menu
 .B dmenu
 .RB [ \-b ]
 .RB [ \-i ]
+.RB [ \-t ]
 .RB [ \-l
 .IR lines ]
 .RB [ \-m
@@ -50,6 +51,9 @@ dmenu appears at the bottom of the scree
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
+.B \-t
+dmenu uses space separated tokens to match menu items.
+.TP
 .BI \-l " lines"
 dmenu lists items vertically, with the given number of lines.
 .TP
--- a/dmenu.c	2010-12-28 17:26:44.368974910 +0000
+++ b/dmenu.c	2010-12-28 17:53:30.548303785 +0000
@@ -30,7 +30,8 @@ static char *fstrstr(const char *s, cons
 static void grabkeyboard(void);
 static void insert(const char *s, ssize_t n);
 static void keypress(XKeyEvent *ev);
-static void match(void);
+static void matchstr(void);
+static void matchtok(void);
 static size_t nextrune(int incr);
 static void paste(void);
 static void readstdin(void);
@@ -62,6 +63,7 @@ static Item *prev, *curr, *next;
 static Window root, win;
 
 static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
+static void (*match)(void) = matchstr;
 
 int
 main(int argc, char *argv[]) {
@@ -78,6 +80,8 @@ main(int argc, char *argv[]) {
 			topbar = False;
 		else if(!strcmp(argv[i], "-i"))
 			fstrncmp = strncasecmp;
+		else if(!strcmp(argv[i], "-t"))
+			match = matchtok;
 		else if(i == argc-1)
 			usage();
 		/* double flags */
@@ -368,7 +372,7 @@ keypress(XKeyEvent *ev) {
 }
 
 void
-match(void) {
+matchstr(void) {
 	size_t len;
 	Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
 
@@ -407,6 +411,33 @@ match(void) {
 	calcoffsets();
 }
 
+void
+matchtok(void) {
+	char buf[sizeof text];
+	char **tokv, *s;
+	int tokc, i;
+	Item *item, *end;
+
+	tokc = 0;
+	tokv = NULL;
+	strcpy(buf, text);
+	for(s = strtok(buf, " "); s; tokv[tokc-1] = s, s = strtok(NULL, " "))
+		if(!(tokv = realloc(tokv, ++tokc * sizeof *tokv)))
+			eprintf("cannot realloc %u bytes\n", tokc * sizeof *tokv);
+
+	matches = end = NULL;
+	for(item = items; item; item = item->next) {
+		for(i = 0; i < tokc; i++)
+			if(!fstrstr(item->text, tokv[i]))
+				break;
+		if(i == tokc)
+			appenditem(item, &matches, &end);
+	}
+	free(tokv);
+	curr = prev = next = sel = matches;
+	calcoffsets();
+}
+
 size_t
 nextrune(int incr) {
 	size_t n, len;
@@ -536,7 +567,7 @@ setup(void) {
 
 void
 usage(void) {
-	fputs("usage: dmenu [-b] [-i] [-l lines] [-m monitor] [-p prompt] [-fn font]\n"
+	fputs("usage: dmenu [-b] [-i] [-t] [-l lines] [-m monitor] [-p prompt] [-fn font]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(EXIT_FAILURE);
 }
