Better notmuch address completion.
This commit is contained in:
parent
92c3456b54
commit
35b464a4e1
@ -1,3 +1,27 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env perl
|
||||||
which lbdbq >/dev/null || exit
|
use Text::vCard::Addressbook;
|
||||||
lbdbq "$1" | sed '1d;s/\(.*\)\t(null).*/\1/;s/\(.*\)\t\(.*\)\t.*/\2 <\1>/'
|
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') || [] };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user