diff -r 1c22b889317b dmenu.c
--- a/dmenu.c	Mon Aug 09 11:54:46 2010 +0100
+++ b/dmenu.c	Mon Aug 09 12:25:34 2010 +0100
@@ -31,7 +31,8 @@
 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 void paste(void);
 static void readstdin(void);
 static void run(void);
@@ -60,6 +61,7 @@
 
 static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
 static char *(*fstrstr)(const char *, const char *) = strstr;
+static void (*match)(void) = matchstr;
 
 void
 appenditem(Item *item, Item **list, Item **last) {
@@ -334,7 +336,7 @@
 }
 
 void
-match(void) {
+matchstr(void) {
 	size_t len;
 	Item *item, *itemend, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
 
@@ -373,6 +375,33 @@
 }
 
 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 = allitems; 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();
+}
+
+void
 paste(void) {
 	char *p, *q;
 	int di;
@@ -494,7 +523,7 @@
 
 void
 usage(void) {
-	fputs("usage: dmenu [-b] [-i] [-l lines] [-p prompt] [-fn font] [-nb color]\n"
+	fputs("usage: dmenu [-b] [-i] [-t] [-l lines] [-p prompt] [-fn font] [-nb color]\n"
 	      "             [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(EXIT_FAILURE);
 }
@@ -518,6 +547,8 @@
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
 		}
+		else if(!strcmp(argv[i], "-t"))
+			match = matchtok;
 		else if(i == argc-1)
 			usage();
 		/* double flags */
