28 lines
		
	
	
		
			859 B
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			28 lines
		
	
	
		
			859 B
		
	
	
	
		
			Perl
		
	
	
		
			Executable File
		
	
	
	
	
#!/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') || [] };
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |