3 Brilliant Open Source Command Line Address Book for Linux

linux terminal address bookModern computer systems employ various tools for managing contacts in our address books. With the proliferation of social media applications, this complexity has increased considerably and lacks the greatest simplicity in style most Linux users adore. This article shows three tools used in the creation of address books from our linux bash terminal.

1) Khard Tool

Khard is an address book for the Linux console. It creates, reads, modifies and removes carddav address book entries at your local machine. Khard is also compatible to the email clients mutt and alot and the SIP client twinkle. Khard is developed and tested on Debian operating system, versions 7, 8 and testing but should run on all Unix-like systems.

Prerequisites

You have to install and configure a caldav and carddav server. I recommend Baikal.
Then you must synchronize the calendars and address books to your local machine with vdirsyncer.
And you need pip to install python modules:

sudo aptitude install python-setuptools
sudo easy_install pip

Installation of Khard

a) From pypi

Khard is installable via pip. I recommend virtualenv to create a separate python3 environment. So your system stays clean. Additionally you don't have to struggle with different python instances, especially if your operating system still defaults to python2.

# install virtualenv package
sudo pip install virtualenv
# create folder for all virtualenv's and put ~/.virtualenvs/bin in your shell's executable path
mkdir ~/.virtualenvs
# create new python3 virtual environment with the name "khard"
virtualenv -p python3 ~/.virtualenvs/khard
# to install khard, use the pip command from that newly created environment
# otherwise it would be installed in the users home directory
~/.virtualenvs/khard/bin/pip install khard
# create subfolder for symlinks of local binaries
# and don't forget to add it to your shell's executable path too
mkdir ~/.virtualenvs/bin
# create a symlink to the local binary folder
ln -s ~/.virtualenvs/khard/bin/khard ~/.virtualenvs/bin

b) From source

If you instead want to run the source code directly, you may install required python modules by hand, clone from git and run the khard-runner.py script:

pip install --user atomicwrites, configobj, pyyaml, vobject
git clone https://github.com/scheibler/khard.git
cd khard/
./khard-runner.py [action [options]]

Configuration

To get the example config file and the other extra data, you can clone from git (see above) or download package from pypi:

pip install --download /tmp --no-deps --no-use-wheel khard
tar xfz /tmp/khard-x.x.x.tar.gz
rm /tmp/khard-x.x.x.tar.gz
cd khard-x.x.x/

Now copy the example config file and adapt it's contents to your needs:

mkdir ~/.config/khard/
cp misc/khard/khard.conf.example ~/.config/khard/khard.conf

Khard also contains a helper script called davcontroller. It's designed to create and remove address books and calendars at the server. I have created davcontroller cause my previously used CalDAV server (Darwin calendarserver) offered no simple way to create new address books and calendars. But davcontroller should be considered as a hacky solution and it's only tested against the Darwin calendarserver. So if your CalDAV server offers a way to create new address books and calendars I recommend to prefer that method over davcontroller.

If you nonetheless want to try davcontroller, you have to install the CalDAVClientLibrary first. Unfortunately, that library isn't compatible to python3 so you have to create an extra python2 virtual environment and install in there:

# create python2 virtual environment
virtualenv -p python2 ~/.virtualenvs/davcontroller
# get library from svn repository
sudo aptitude install subversion
svn checkout http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk CalDAVClientLibrary
cd CalDAVClientLibrary
# install library
~/.virtualenvs/davcontroller/bin/python setup.py install
# start davcontroller script
~/.virtualenvs/davcontroller/bin/python /path/to/khard-x.x.x/misc/davcontroller/davcontroller.py

 Show contacts

After you have created a new address book or calendar and you have synced it to your local machine, you can list all available contacts with the following command:

khard list

or if you have more than one address book and you want to filter the output:

khard list -a addressbook1,addressbook2

The resulting contact table only contains the first phone number and email address. If you want to view all contact details you can pick one from the list:

khard details

or search for it:

khard details [--strict-search] name of contact

or select the contact by it's uid, which you can find at the contacts table:

khard details -u ID

The parameters -a and -u from the examples above are always optional. If you don't use them or your input produces unambiguous results, you may pick the contacts from a list instead.

The search parameter searches in all data fields. Therefore you aren't limited to the contact's name but you also could for example search for a part of a phone number, email address or post address. However if you explicitly want to narrow your search to the name field, you may use the --strict-search parameter instead.

Create contact

Add new contact with the following command:

khard new [-a "address book name"]

The template for the new contact opens in the text editor, which you can set in the khard.conf file. It follows the yaml syntax.

Alternatively you can create the contact from stdin:

echo """
First name : John
Last name  : Smith
Email :
    work : john.smith@example.org
Phone :
    home : xxx 555 1234
Categories :
    - cat1
    - cat2
    - cat3
""" | khard new [-a "address book name"]

or create from input template file:

khard new -i contact.yaml [-a "address book name"]

You may get an empty contact template with the following command:

khard export --empty-contact-template -o empty.yaml

Per default khard creates vcards of version 3.0. If your other contact applications support vcards of the more recent version 4.0, you may change this with the option --vcard-version. Example:

khard new --vcard-version=4.0 [-a "address book name"]

For a more permanent solution you may set the preferred_version parameter in the vcard section of the khard config file (see misc/khard/khard.conf.example for more details). But beware, that khard cannot convert already existing contacts from version 3.0 to 4.0. Therefore this setting is not applicable to the modify action.

Edit contacts

Use the following to modify the contact after successful creation:

khard modify [-a addr_name] [-u uid|search terms [search terms ...]]

If you want to edit the contact elsewhere, you can export the filled contact template:

khard export -o contact.yaml [-a addr_name] [-u uid|search terms [search terms ...]]

Edit the yaml file and re-import either through stdin:

cat contact.yaml | khard modify [-a addr_name] [-u uid|search terms [search terms ...]]

or file name:

khard modify -i contact.yaml [-a addr_name] [-u uid|search terms [search terms ...]]

If you want to merge contacts use the following to select a first and then a second contact:

khard merge [-a source_abook] [-u uid|search terms [search terms ...]] [-A target_abook] [-U target_uid|-t target_search_terms]

You will be launched into your merge_editor ( see the "merge_editor" option in khard.conf) where you can merge all changes from the first selected contact onto the second. Once you are finished, the first contact is deleted and the second one updated.

Copy or move contact:

khard copy [-a source_abook] [-u uid|search terms [search terms ...]] [-A target_abook]
khard move [-a source_abook] [-u uid|search terms [search terms ...]] [-A target_abook]

Remove contact:

khard remove [-a addr_name] [-u uid|search terms [search terms ...]]

This small script helps to create and remove new address books and calendars at the carddav and caldav server.

List available resources

davcontroller -H example.com -p 11111 -u USERNAME -P PASSWORD list

Possible actions are: list, new-addressbook, new-calendar and remove. After creating or removing you must adapt your vdirsyncer config.

Set as external address book

Khard may be used as an external address book for the email client mutt. To accomplish that, add the following to your mutt config file (mostly ~/.mutt/muttrc):

set query_command= "khard email --parsable %s"
bind editor <Tab> complete-query
bind editor ^T    complete

Then you can complete email addresses by pressing the Tab-key in mutt's new mail dialog. If your address books contain hundreds or even thousands of contacts and the query process is very slow, you may try the --search-in-source-files option to speed up the search:

set query_command= "khard email --parsable --search-in-source-files %s"

To add email addresses to khard's address book, you may also add the following lines to your muttrc file:

macro index,pager A \
    "<pipe-message>khard add-email<return>" \
    "add the sender email address to khard"

Then navigate to an email message in mutt's index view and press "A" to start the address import dialog.

2) Ppl Tool

ppl address book depends on `rubygems` for installation; `git` for storage and syncing.

Installation

$ sudo gem install ppl

Create An Address Book

$ ppl init ~/contacts

`ppl init` is just like creating a Git repo

Adding Contacts

$ cd ~/contacts
$ ppl add alice "Alice Adams"
$ ppl add bob "Bob Brown"
$ ppl add eve "Eve Edwards"

ppl add creates new contacts in the address book

Store Some Contact Details

$ ppl email alice alice@example.org
$ ppl phone bob 0123456789
$ ppl org eve "Red Hat"

ppl has many commands for adding new properties to contacts. Further information is available in the documentation

Set Your Default Address Book

$ echo "[address book]" > ~/.pplconfig
$ echo path = "`pwd`" >> ~/.pplconfig

This tells ppl to let you keep working with this address book even after you cd into another directory

3) Terminal velocity

Terminal Velocity is a fast note-taking app for the UNIX terminal, that focuses on letting you create or find a note as quickly and easily as possible, then uses your

$EDITOR

to open and edit the note. It is heavily inspired by the OS X app Notational Velocity.

Installation

To install Terminal Velocity, run:

pip install terminal_velocity

Then to launch it just run:

terminal_velocity

To use a different notes directory, run:

terminal_velocity path/to/your/notes/dir

To see all the command-line options, run:

terminal_velocity -h

To quit the app, press

ctrl-c or ctrl-x.

Create Notes

To create a new note, type a title for the note and hit enter. The note will be opened in your text editor. As you type the title, the list of notes filters to show notes that match what you've typed, giving you a chance to open a related note instead of making a new one.

Find Notes

The same text area is used for entering the titles of new notes and for searching notes. To find and open a note, type some words from the note's title or contents. The list of notes filters as you type to show only matching notes. When you see the note that you want, use the up and down arrows to select it then hit enter to open it. You can also use page up and page down or mouse clicks to select notes.

Autocomplete

If you type the beginning of a note's title (case-insensitive), that note will be automatically selected in the note list and its title will be autocompleted in the search box. Whenever a note is selected, just hit enter to open that note.

If you want to create a new note whose title is a substring of an existing note's title, then even after you've typed the full title for your new note the existing note will still be selected by the autocomplete. In this case, you have to hit ctrl-d or escape to clear the autocomplete selection, then hitenter to create your note.

 Conclusion

Linux provides many tools for creating and maintaining notes; in addition to those listed above there are other tools such as devtodo which is used by developers to maintain a  list of tasks in order of importance. The traditional Linux users prefer the simple command line interface of the Linux terminal with its lightweight tools. However recent developments in the Linux ecosystem has brought many GUI tools for managing address books. Even though they might appear simple to some non-technical computer users; the terminal based tools remain a classic and preference for most experienced Linux users.

About Nyah Check

Founder of Buea Docker Meetup and Golang Buea (Buea Gophers Meetup). Interested in Cloud and Container technologies.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.