Anonymous committed 2e12a0e

Added -n option to include contacts who have no email address.

  • Participants
  • Parent commits ef8a172

Comments (0)

Files changed (2)

 abook = '~/.abook/addressbook'
 email = lambda {|who| who['email']}
+noemail = false
 optparse = do |opts|
-  opts.banner = 'usage: aqua [-1] [-f addressbook] term...'
+  opts.banner = 'usage: aqua [-1n] [-f addressbook] term...'
   opts.on('-1', '--first', 'Only retrieve the first email for each person') do
     email = lambda {|who| who['email'].sub /,.*/, '' }
     abook = file
+  opts.on('-n', '--noemail', 'Include contacts who don\'t have an email address') do
+    noemail = true
+  end
 begin abook).each do |line|
   case line.chomp.strip
     when /^$/
-      found << "#{ who}\t#{who['name']}\t#{who['notes']}" if who && who['email'] &&
+      found << "#{ who}\t#{who['name']}\t#{who['notes']}" if who && (who['email'] || noemail) &&
     when /^\[\d+\]/
       who = {}
     when /^(\w+?)=(.+)/
 .Op Fl 1
 .Op Fl f Ar addressbook
+.Op Fl n
 .Op Ar term...
 The aqua utility provides a drop-in replacement for abook's mutt-query option.  Whereas abook only searches its name and email fields,
 aqua can search all fields.  You can also specify which specific fields to search, combine searches with and/or and parenthesized grouping,
-and include regular expressions.  aqua only returns contacts who have at least one email address.
+and include regular expressions.  aqua only returns contacts who have at least one email address, unless you specify the -n option.
 .Bl -tag -width indent
 .It Fl 1, -first
 Only return the first email address for each matching entry.  By default, all addresses are returned, separated by commas.
 .It Fl f, -file Ar addressbook
 Specify the address book to search.  The default is ~/.abook/addressbook
+.It Fl n, -noemail
+Include contacts that have no email address
 Search terms can be simple strings, which will be treated as case-insensitive with leading and trailing spaces removed.  If a string
 begins and ends with parentheses, those will also be removed from the search.  Thus, you can force a search for leading or trailing