Re: [PATCH] test: fix compact backup / restore test
[notmuch-archives.git] / c0 / 4f99a530ed6c36dadf6316149e3c0714783362
1 Return-Path: <peterjohnhartman@gmail.com>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id A0742429E25\r
6         for <notmuch@notmuchmail.org>; Sat,  1 Oct 2011 07:29:11 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id WRr-rh2U9lHW for <notmuch@notmuchmail.org>;\r
17         Sat,  1 Oct 2011 07:29:10 -0700 (PDT)\r
18 Received: from mail-qw0-f53.google.com (mail-qw0-f53.google.com\r
19         [209.85.216.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 9D017431FB6\r
22         for <notmuch@notmuchmail.org>; Sat,  1 Oct 2011 07:29:10 -0700 (PDT)\r
23 Received: by qafi31 with SMTP id i31so1117678qaf.26\r
24         for <notmuch@notmuchmail.org>; Sat, 01 Oct 2011 07:29:09 -0700 (PDT)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=date:from:to:subject:message-id:mime-version:content-type\r
27         :content-disposition:content-transfer-encoding:user-agent;\r
28         bh=7Z16G0kWwpuK+c9yPTmsU3umWxcJOK2cpgqZtNsGHDg=;\r
29         b=ACef3DvQsWtCogz+nqTVnPumDuCW905jniOlWQPAyhz/uth5wafaHjCKepatrFs7zC\r
30         nEogpRCssCOyHKEPHS7s8uFk27A6LYIXxIjXJ6PJ4VbPUYxb5cup+cjdUqRQI8i4V+Ig\r
31         uvDsTyzZQWnZZoB1N8wtDT7ZFgEj2LciGR7cU=\r
32 Received: by 10.224.203.196 with SMTP id fj4mr9875374qab.362.1317479348788;\r
33         Sat, 01 Oct 2011 07:29:08 -0700 (PDT)\r
34 Received: from localhost (ip-64-134-98-119.public.wayport.net.\r
35  [64.134.98.119])       by mx.google.com with ESMTPS id\r
36  du5sm9189819qab.14.2011.10.01.07.29.07 (version=SSLv3 cipher=OTHER); Sat, 01\r
37  Oct 2011 07:29:08 -0700 (PDT)\r
38 Date: Sat, 1 Oct 2011 10:29:06 -0400\r
39 From: Peter John Hartman <peterjohnhartman@gmail.com>\r
40 To: notmuch@notmuchmail.org\r
41 Subject: an alternative commandline interface to notmuch\r
42 Message-ID: <20111001142906.GA635@leneee.sbx07386.newyony.wayport.net>\r
43 MIME-Version: 1.0\r
44 Content-Type: text/plain; charset=iso-8859-1\r
45 Content-Disposition: inline\r
46 Content-Transfer-Encoding: 8bit\r
47 User-Agent: Mutt/1.5.21 (2010-09-15)\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52         <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Sat, 01 Oct 2011 14:29:11 -0000\r
61 \r
62 Hi folks,\r
63 \r
64 Rafa released slmenu, a dmenu-clone that runs on the commandline, and I\r
65 contributed a couple of patches (verticality and tokens) to make it work\r
66 nice with notmuch.  So far, I'm pretty happy.  To get slmenu:\r
67 \r
68 hg clone http://hg.suckless.org/slmenu\r
69 \r
70 You'll need to apply the patch at the bottom of this e-mail[1].\r
71 You'll also want to use the shell script (nmsl) at the bottom of this e-mail[2].\r
72 \r
73 How it works:\r
74 \r
75 Basically, it pipes output (after being mangled a bit) from notmuch search\r
76 into slmenu/dmenu (so you can select the thread) and then sends that output \r
77 to mutt, either via mbox (if notmuch is hosted remote) or maildir (if local).\r
78 It also allows you to prepend an entry with v (tag viewed), t +tag (tag\r
79 tag), x (tag x-del).\r
80 \r
81 All this will be at:\r
82 \r
83 http://durandus.trilidun.org/durandus/code/notmuch-slmenu/\r
84 Best,\r
85 Peter\r
86 \r
87 \r
88 \r
89 [1] token.patch to slmenu\r
90 \r
91 diff -r 7896c4e3bf21 slmenu.c\r
92 --- a/slmenu.c  Thu Sep 29 12:45:34 2011 +0200\r
93 +++ b/slmenu.c  Sat Oct 01 10:11:29 2011 -0400\r
94 @@ -36,7 +36,7 @@\r
95  static void   drawmenu(void);\r
96  static char  *fstrstr(const char*, const char*);\r
97  static void   insert(const char*, ssize_t);\r
98 -static void   match(int);\r
99 +static void   match(void); \r
100  static size_t nextrune(int);\r
101  static void   readstdin(void);\r
102  static int    run(void);\r
103 @@ -60,10 +60,10 @@\r
104  \r
105  void\r
106  appenditem(Item *item, Item **list, Item **last) {\r
107 -       if(!*last)\r
108 +       if(*last)\r
109 +               (*last)->right = item;\r
110 +       else\r
111                 *list = item;\r
112 -       else\r
113 -               (*last)->right = item;\r
114         item->left = *last;\r
115         item->right = NULL;\r
116         *last = item;\r
117 @@ -132,13 +132,17 @@\r
118         Item *item;\r
119         int rw;\r
120  \r
121 +       fprintf(stderr, "\033[H"); \r
122 +       fprintf(stderr, "\033[2J"); \r
123 +\r
124         /* use default colors */\r
125         fprintf(stderr, "\033[0m");\r
126 +/*     setupterm(); \r
127 +       putp(clear_screen);  */\r
128  \r
129         /* place cursor in first column, clear it */\r
130         fprintf(stderr, "\033[0G");\r
131         fprintf(stderr, "\033[K");\r
132 -\r
133         if(prompt)\r
134                 drawtext(prompt, promptw-4, C_Reverse);\r
135  \r
136 @@ -188,9 +192,10 @@\r
137         if(n > 0)\r
138                 memcpy(&text[cursor], str, n);\r
139         cursor += n;\r
140 -       match(n > 0 && text[cursor] == '\0');\r
141 +       match();\r
142  }\r
143  \r
144 +/*\r
145  void\r
146  match(int sub) {\r
147         size_t len = strlen(text);\r
148 @@ -231,6 +236,60 @@\r
149         curr = sel = matches;\r
150         calcoffsets();\r
151  }\r
152 +*/\r
153 +\r
154 +void\r
155 +match(void) {\r
156 +       static char **tokv = NULL;\r
157 +       static int tokn = 0;\r
158 +\r
159 +       char buf[sizeof text], *s;\r
160 +       int i, tokc = 0;\r
161 +       size_t len;\r
162 +       Item *item, *lprefix, *lsubstr, *prefixend, *substrend;\r
163 +       \r
164 +       strcpy(buf, text);\r
165 +       for(s = strtok(buf, " "); s; tokv[tokc-1] = s, s = strtok(NULL, " "))\r
166 +               if(++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))\r
167 +                       die("Can't realloc.");\r
168 +/*                     fprintf("cannot realloc %u bytes\n", tokn * sizeof *tokv); */\r
169 +       len = tokc ? strlen(tokv[0]) : 0;\r
170 +       \r
171 +       matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;\r
172 +       for(item = items; item && item->text; item++) {\r
173 +               for(i = 0; i < tokc; i++)\r
174 +                       if(!fstrstr(item->text, tokv[i]))\r
175 +                               break;\r
176 +               if (i != tokc)\r
177 +                       continue;\r
178 +               if(!tokc || !fstrncmp(tokv[0], item->text, len+1))\r
179 +                       appenditem(item, &matches, &matchend);\r
180 +               else if(!strncmp(tokv[0], item->text, len))\r
181 +                       appenditem(item, &lprefix, &prefixend);\r
182 +               else\r
183 +                       appenditem(item, &lsubstr, &substrend);\r
184 +       }\r
185 +       if(lprefix) {\r
186 +               if(matches) {\r
187 +                       matchend->right = lprefix;\r
188 +                       lprefix->left = matchend;\r
189 +               }\r
190 +               else\r
191 +                       matches = lprefix;\r
192 +               matchend = prefixend;\r
193 +       }\r
194 +       if(lsubstr) {\r
195 +               if(matches) {\r
196 +                       matchend->right = lsubstr;\r
197 +                       lsubstr->left = matchend;\r
198 +               }\r
199 +               else\r
200 +                       matches = lsubstr;\r
201 +               matchend = substrend;\r
202 +       }\r
203 +       curr = sel = matches;\r
204 +       calcoffsets();\r
205 +}\r
206  \r
207  size_t\r
208  nextrune(int inc) {\r
209 @@ -371,7 +430,7 @@\r
210                 case CONTROL('J'):\r
211                         if(sel) strncpy(text, sel->text, sizeof text); /* Complete the input first, when hitting return */\r
212                         cursor = strlen(text);\r
213 -                       match(TRUE);\r
214 +                       match();\r
215                         drawmenu();\r
216                         /* fallthrough */\r
217                 case CONTROL(']'):\r
218 @@ -441,11 +500,11 @@\r
219                                 break;\r
220                         strncpy(text, sel->text, sizeof text);\r
221                         cursor = strlen(text);\r
222 -                       match(TRUE);\r
223 +                       match(); \r
224                         break;\r
225                 case CONTROL('K'):\r
226                         text[cursor] = '\0';\r
227 -                       match(FALSE);\r
228 +                       match(); \r
229                         break;\r
230                 case CONTROL('U'):\r
231                         insert(NULL, 0 - cursor);\r
232 @@ -514,7 +573,7 @@\r
233         lines=MIN(MAX(lines, 0), mh);\r
234         promptw=(prompt?textw(prompt):0);\r
235         inputw=MIN(inputw, mw/3);\r
236 -       match(FALSE);\r
237 +       match();\r
238         if(barpos!=0) resetline();\r
239         drawmenu();\r
240  }\r
241 @@ -542,7 +601,7 @@\r
242                         puts("slmenu, © 2011 slmenu engineers, see LICENSE for details");\r
243                         exit(EXIT_SUCCESS);\r
244                 }\r
245 -               else if(!strcmp(argv[i], "-i"))\r
246 +               else if(!strcmp(argv[i], "-i")) \r
247                         fstrncmp = strncasecmp;\r
248                 else if(!strcmp(argv[i], "-t"))\r
249                         barpos=1;\r
250 \r
251 [2] nmsl shell script\r
252 #!/bin/sh\r
253 # Copyright (c) Peter John Hartman (peterjohnhartman at gmail dot com)\r
254 #\r
255 # * Permission to use, copy, modify, and distribute this software for any\r
256 # * purpose with or without fee is hereby granted, provided that the above\r
257 # * copyright notice and this permission notice appear in all copies.\r
258 # *\r
259 # * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\r
260 # * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\r
261 # * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\r
262 # * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\r
263 # * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER\r
264 # * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING\r
265 # * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\r
266 \r
267 maildir="/tmp/maildir"\r
268 slmenu="slmenu -i -l 30 -t -p [vtx]:"\r
269 #slmenu="dmenu -i -l 30 -p [vtx]:"\r
270 notmuch="/usr/local/bin/notmuch"\r
271 use_maildir=1\r
272 usage() {\r
273   cat << EOF\r
274   usage: $0 options\r
275 \r
276   Example: nmsl `nmdate 3 days ago`..`nmdate yesterday` tag:inbox\r
277   Example: nmsl tag:inbox and tag:unread\r
278 \r
279   nmdate = echo $(date +%s -d "$*")\r
280 \r
281   OPTIONS:\r
282      -h      Show this message\r
283      -s      Use ssh\r
284 EOF\r
285 }\r
286 \r
287 while getopts "hsd:" OPTION\r
288 do\r
289   case $OPTION in\r
290     h) \r
291       usage\r
292       exit 1\r
293       ;;\r
294     s)\r
295       notmuch="ssh trillap /usr/local/bin/notmuch"\r
296       use_maildir=0\r
297       ;;\r
298   esac\r
299 done\r
300 \r
301 shift $((OPTIND-1))\r
302 search=$@\r
303 \r
304 if [[ $search == "" ]]; then\r
305   search="tag:inbox and tag:unread"\r
306 fi\r
307 \r
308 res=$($notmuch search $search |\\r
309   sed -r 's/([^ ]*) ([^[]*)([^]]*\]) ([^;]*); (.*) (\([^)]*\))/\2\5; \4 \3 \6 \1/' |\\r
310   $slmenu)\r
311 \r
312 if [[ $res != "" ]]; then\r
313         option=$(echo $res | cut -d' ' -f1)\r
314 \r
315         case "$option" in\r
316           x) \r
317           # delete\r
318                 thread=$(echo $res | awk -F' ' '{print $NF}')\r
319                 notmuch tag -unread +x-del $thread\r
320                 nmsl $*\r
321           ;;\r
322           t)\r
323           # tag;\r
324                 thread=$(echo $res | awk -F' ' '{print $NF}')\r
325                 notmuch tag $(echo $res | cut -d' ' -f2) -inbox $thread\r
326                 nmsl $*\r
327           ;;\r
328           v)\r
329           # quick -unread\r
330                 thread=$(echo $res | awk -F' ' '{print $NF}')\r
331                 notmuch tag -unread $thread\r
332                 nmsl $*\r
333           ;;\r
334           *)\r
335                 thread=$(echo $res | awk -F' ' '{print $NF}')\r
336                 clear\r
337                 if [[ $use_maildir -eq 1 ]]; then\r
338                         rm -rf $maildir\r
339                         mkdir $maildir\r
340                         mkdir $maildir/cur\r
341                         mkdir $maildir/new\r
342                         mkdir $maildir/tmp\r
343                         $notmuch search --output=files $thread | sed -e 's: :\\ :g' |\\r
344                                 xargs --no-run-if-empty ln -s -t $maildir/cur/\r
345                         mutt -f $maildir\r
346                 else\r
347                         $notmuch show --format=mbox $thread > /tmp/nmsearch.$$\r
348                         mutt -f /tmp/nmsearch.$$\r
349                         rm -f -- /tmp/nmsearch.$$\r
350                 fi\r
351                 nmsl $*\r
352           ;;\r
353         esac\r
354 fi\r
355 \r
356 clear\r
357 \r
358 \r
359 \r
360 \r
361 \r
362 \r
363 \r
364 -- \r
365 sic dicit magister P\r
366 University of Toronto / Fordham University\r
367 Collins Hall B06; Office Hours TF10-12\r
368 http://individual.utoronto.ca/peterjh\r
369 gpg  1024D/ED6EF59B  (7D1A 522F D08E 30F6 FA42  B269 B860 352B ED6E F59B)\r
370 gpg --keyserver pgp.mit.edu --recv-keys ED6EF59B\r