Better notmuch address completion.

This commit is contained in:
Gabriel Ebner 2013-04-30 20:29:02 +02:00
parent 92c3456b54
commit 35b464a4e1
1 changed files with 27 additions and 3 deletions

View File

@ -1,3 +1,27 @@
#!/bin/sh
which lbdbq >/dev/null || exit
lbdbq "$1" | sed '1d;s/\(.*\)\t(null).*/\1/;s/\(.*\)\t\(.*\)\t.*/\2 <\1>/'
#!/usr/bin/env perl
use Text::vCard::Addressbook;
my $address_book =
Text::vCard::Addressbook->load( ["$ENV{HOME}/.contacts.vcf"] );
my $query = $ARGV[0];
if ( my ($category) = ( $query =~ /^#(.*)/ ) ) {
my @members;
foreach my $vcard ( $address_book->vcards() ) {
for ( @{ $vcard->get('categories') || [] } ) {
next unless $_->value() =~ /(^|,)$category/i;
if ( my $email = $vcard->get_simple_type('email') ) {
push @members, sprintf "%s <%s>", $vcard->fullname(), $email;
}
}
}
print join( ', ', @members ), "\n" if @members;
}
else {
foreach my $vcard ( $address_book->vcards() ) {
if ( $vcard->fullname() =~ /$query/i ) {
printf "%s <%s>\n", $vcard->fullname(), $_->value()
for @{ $vcard->get('email') || [] };
}
}
}