~jcc/addr-book-combine

Combine multiple aerc-style address books into a single address book, with de-duplication and smart sorting.
Add contributing info
Print usage without logging info (e.g. timestamp)
Don't fail when command exits with non-zero status

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~jcc/addr-book-combine
read/write
git@git.sr.ht:~jcc/addr-book-combine

You can also use your local clone with git send-email.

#addr-book-combine

jasoncarloscox.com/creations/addr-book-combine

Combine multiple aerc-style address books into a single address book, with de-duplication and smart sorting.

Works well with maildir-rank-addr.

#Usage

addr-book-combine (-f <file> | -c <command>) ...
  • <file> is the path to a file containing address book entries.
  • <command> is a command (to be run with sh -c) that outputs address book entries on stdout.

Each argument (-f <file> or -c <command>) is considered a separate address book. Each book contains entries, each on their own line. Entries have tab-separated fields (address<tab>name<tab>rank). Here's an example address book:

a@example.com	Andy Apple	5
b@example.com	Bart Berry	2
c@example.com	Chad Cherry	4
d@example.com

(Names and ranks are optional.)

#Sorting

When comparing two addresses, a and b, which appear in books numbered i and j, respectively, the following procedure is applied:

  1. First, if the addresses are not from the same book, the address from the earlier book appears first.

  2. Next, each book is checked to compare the addresses:

    • If neither address is ranked within the book, check in the next book.
    • If only one address is ranked within the book, the ranked address appears first.
    • If both addresses have the same rank, check in the next book.
    • If the addresses have different ranks, the address with the lowest rank appears first.
  3. Finally, if no address has been chosen to appear first, preserve the original order of the addresses.

Check out the test code to see some examples.

#Building & Running

go build
./addr-book-combine

#Testing

go test

#Contributing

Contributions are welcome! You can send questions, bug reports, patches, etc. by email to ~jcc/public-inbox@lists.sr.ht. (Don't know how to contribute via email? Check out the interactive tutorial at git-send-email.io, or email me for help.)