May 6, 2025

A CRM on the command-line, with abook

I wanted a CRM I can use on the command-line.

I already use abook (with Mutt) and I have my contacts stored in a text file so I wanted to build on the top that; I did not want to have to create a new file (or a database).

What’s my setup?

Add tags to abook

First I added a field in abook so I can tag contacts in abook:

The relevant part of my ~/.abook/abookrc looks like this:

# Define custom fields
field tag = tag, list
field organisation = organisation, list

# Define how fields should be displayed in tabs
view CONTACT = name, email, organisation
view ADDRESS = address, address2, city, state, zip, country
view PHONE = phone, workphone, mobile
view OTHERS = nick, url, notes, anniversary, groups
view TAG = tag 

Query CRM and display output

Then I wanted to query a tag or a keyword, for example a city, and display the names of contacts that match the query as a list in the terminal.

I created a file to store the script:

$ cd ~/bin/
$ touch crm

and added the following script to the file crm:

#!/bin/bash
awk -v RS='' '{ gsub("\n", "\034"); print }' /home/user/.abook/addressbook | grep -i $* | sed 's/$/\n/' | tr \\034 \\n | grep name | cut -d= -f2 | less --quit-if-one-screen -RX

Note: if you use this script,

  • replace user by your username.
  • make sure to update the location of file addressbook, if it’s not the same.

I made the script executable:

$ chmod +x crm

Use the script

Now I can display the list of name of a contact based on a tag by running:

$ crm keyword 

keyword is case insensitive.1

Shortcomings

crm keyboard queries any string in the file ~/.abook/addressbook, so any contacts containing a string that matches the keyword in their contact records will be returned. When this is an issue, I append the field of the keyword I am querying, for example:

$ crm tag=supplier

if I want to list all suppliers, or:

$ crm city=naples

if I want to list of contacts are based in Naples.

Next step

Next step would be to render the output in abook, and be able to update addressbook when the output is edited.

Feedback welcome.


  1. Credit: https://trisquel.info/en/forum/simple-crm-command-line-abook-awk-wip-2#comment-179278↩︎


personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki abook

No affiliate links, no analytics, no tracking, no cookies. This work © 2016-2025 by yctct is licensed under CC BY-SA 4.0 .   about me   contact me   all entries & tags   FAQ   GPG public key

GPG fingerprint: 2E0F FB60 7FEF 11D0 FB45 4DDC E979 E52A 7036 7A88