nottoomuch-addresses-1.1.pl nottoomuch-addresses-1.2.sh
1#!/usr/bin/perl1#!/bin/sh
2# -*- cperl -*-2# -*- cperl -*-
3
4case $* in ''|--*) exec perl -x "$0" "$@" ;;
5 ???*)
6 exec grep -aiF "$*" "${XDG_CONFIG_HOME:-$HOME/.config}/nottoomuch/addresses"
7esac
8exit 0
9
3# $ nottoomuch-addresses.pl $10# $ nottoomuch-addresses.sh $
4#11#
5# Created: Thu 27 Oct 2011 17:38:46 EEST too12# Created: Thu 27 Oct 2011 17:38:46 EEST too
6# Last modified: Fri 02 Dec 2011 19:11:33 EET too13# Last modified: Tue 06 Dec 2011 20:00:00 EET too
714
8# Add this to your notmuch elisp configuration file:15# Add this to your notmuch elisp configuration file:
9#16#
10# (require 'notmuch-address)17# (require 'notmuch-address)
11# (setq notmuch-address-command "/path/to/nottoomuch-addresses.pl")18# (setq notmuch-address-command "/path/to/nottoomuch-addresses.sh")
12# (notmuch-address-message-insinuate)19# (notmuch-address-message-insinuate)
1320
14# Documentation at the end. HISTORY after BEGIN block below. Encoding: utf-8.21# Documentation at the end. Encoding: utf-8.
15
16#BEGIN { system '/bin/sh', '-c', 'env > $HOME/na-ENV.$$'; }
17
18my ($configdir, $adbpath);
19
20# optimize search case -- no need to compile further in this case.
21BEGIN {
22 $configdir = ($ENV{XDG_CONFIG_HOME}||$ENV{HOME}.'/.config').'/nottoomuch';
23 $adbpath = $configdir . '/addresses';
24
25 if (@ARGV and $ARGV[0] !~ /^--/)
26 {
27 my $search_str = "@ARGV";
28 exit 0 unless length $search_str >= 3; # more than 2 chars required...
29
30 unless (open I, '<', $adbpath) {
31 print "Cannot open database, maybe not created yet.\n";
32 print "run $0 --update from command line first.\n";
33 exit 0;
34 }
35 print grep { index($_, $search_str) >= 0 } <I>;
36 close I;
37 exit 0;
38 }
39}
4022
41# HISTORY23# HISTORY
42#24#
25# Version 1.2 2011-12-06 18:00:00 UTC
26# * Changed search work case-insensitively -- grep(1) does it locale-aware.
27# * Changed this program execute from /bin/sh (wrapper).
28#
43# Version 1.1 2011-12-02 17:11:33 UTC29# Version 1.1 2011-12-02 17:11:33 UTC
44# * Removed Naïve assumption that on-one runs update on 'dumb' terminal.30# * Removed Naïve assumption that no-one runs update on 'dumb' terminal.
45# * Check address database file first line whether it is known to us.31# * Check address database file first line whether it is known to us.
46#32#
47# Thanks to Bart Bunting for providing a good bug report.33# Thanks to Bart Bunting for providing a good bug report.
48#34#
49# Version 1.0 2011-11-30 20:56:10 UTC35# Version 1.0 2011-11-30 20:56:10 UTC
50# * Initial release36# * Initial release
37
38#!perl
5139
52use 5.8.1;40use 5.8.1;
53use strict;41use strict;
58use MIME::QuotedPrint 'decode_qp';46use MIME::QuotedPrint 'decode_qp';
5947
60no encoding;48no encoding;
49
50my $configdir = ($ENV{XDG_CONFIG_HOME}||$ENV{HOME}.'/.config').'/nottoomuch';
51my $adbpath = $configdir . '/addresses';
6152
62unless (@ARGV)53unless (@ARGV)
63{54{
298 undef %seen;289 undef %seen;
299 my $etime = time;290 my $etime = time;
300 open O, '>', $adbpath or die "Cannot write to '$adbpath': $!\n";291 open O, '>', $adbpath or die "Cannot write to '$adbpath': $!\n";
301 print O $etime, "\n";292 printf O "%010d\n", $etime;
302 print O join("\n", sort @list), "\n";293 print O join("\n", sort @list), "\n";
303 close O;294 close O;
304 my $ecount = scalar @list;295 my $ecount = scalar @list;
317308
318=head1 NAME309=head1 NAME
319310
320nottoomuch-addresses.pl -- address completion/matching (for notmuch)311nottoomuch-addresses.sh -- address completion/matching (for notmuch)
321312
322=head1 SYNOPSIS313=head1 SYNOPSIS
323314
324nottoomuch-addresses.pl ( --update [--rebuild] | <search string> )315nottoomuch-addresses.sh ( --update [--rebuild] | <search string> )
325316
326B<nottoomuch-addresses.pl --help> for more help317B<nottoomuch-addresses.sh --help> for more help
327318
328=head1 VERSION319=head1 VERSION
329320
3301.0 (2011-11-30)3211.2 (2011-12-06)
331322
332=head1 OPTIONS323=head1 OPTIONS
333324

Generated by htmldiff.sh