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. You can find more information about khard and the whole synchronization process here.
Khard is developed and tested on Debian operating system, version 7 and 8 but should run on all Unix-like systems.
If you encounter bugs, please contact me via email: email (at) eric-scheibler (dot) de.
You have to install and configure a caldav and carddav server. I recommend Baïkal.
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
Khard is installable via pip. You can choose between the following three methods:
-
Install system wide:
sudo pip install khard
But that's not recommended due to security issues and cause it can damage dependencies of other python modules.
-
Install into user space:
pip install --user khard
Then you can find the executable under ~/.local/bin.
-
Use virtualenv to create a separate python environment for every module. That's recommended cause it keeps your system clean:
# install virtualenv package sudo pip install virtualenv # create folder for all virtualenv's mkdir ~/.virtualenvs # create new virtual environment with the name "khard" virtualenv ~/.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 a symlink to the local binary folder ln -s ~/.virtualenvs/khard/bin/khard ~/bin
More information about virtualenv at http://docs.python-guide.org/en/latest/dev/virtualenvs/
To get the example config file and the twinkle plugin you can clone from git:
git clone https://github.com/scheibler/khard.git
cd khard/
Or download and extract with pip:
pip install --download /tmp --no-deps --no-use-wheel khard
tar xfz /tmp/khard-0.2.1.tar.gz
rm /tmp/khard-0.2.1.tar.gz
cd khard-0.2.1/
Now copy the example config file and adapt it's contents to your needs:
mkdir ~/.config/khard/
cp misc/khard.conf.example ~/.config/khard/khard.conf
Khard also contains a helper utility 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:
sudo aptitude install subversion
svn checkout http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk CalDAVClientLibrary
cd CalDAVClientLibrary
For user space installation:
python setup.py install --user
Or if you use the virtual environment:
~/.virtualenvs/khard/bin/python setup.py install
ln -s ~/.virtualenvs/khard/bin/davcontroller ~/bin
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
Searching is possible too:
khard list -s "name of contact"
The list only shows the first phone number and email address. If you want to view all contact details you type:
khard details -a addressbook1 -s "name of 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.
Alternatively you also could create the contact from stdin. Take the syntax from the contact template file. Example:
echo "first name = John\nlast name = Smith\n" \
"email1 = work: john.smith@example.org\n" \
"phone1 = home: xxx 555 1234\n" \
"Categories = cat1, cat2, cat3" \
| khard new -a "address book name"
Use the following to modify the contact after successful creation:
khard modify -s "name of contact"
If you wish to merge contacts use the following to select a first and then a second contact:
khard merge -s "from contact,into contact"
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 -s "source contact,target address book"
khard move -s "source contact,target address book"
Remove contact:
khard remove -s "name of contact"
The parameters -a and -s from the examples above are always optional (only exception is -a for the new command). 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.
This small utility 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.
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 --search '%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.
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.
Add the following lines to your alot config file:
[accounts]
[[youraccount]]
[[[abook]]]
type = shellcommand
command = khard email -s
regexp = '^(?P<email>[^@]+@[^\t]+)\t+(?P<name>[^\t]+)'
ignorecase = True
For those who also use the SIP client twinkle to take phone calls, khard can be used to query incoming numbers. The plugin tries to find the incoming caller id and speaks it together with the phone's ring tone. The plugin needs the following programs:
sudo aptitude install ffmpeg espeak sox mpc
sox and ffmpeg are used to cut and convert the new ring tone and espeak speaks the caller id. mpc is a client for the music player daemon (mpd). It's required to stop music during an incoming call. Skip the last, if you don't use mpd. Don't forget to set the "stop_music"-parameter in the config.py file to False too.
After the installation, copy the scripts and sounds folders to your twinkle config folder:
cp -R misc/twinkle/* ~/.twinkle/
Then edit your twinkle config file (mostly ~/.twinkle/twinkle.cfg) like this:
# RING TONES
# We need a default ring tone. Otherwise the phone would not ring at all, if something with the
# custom ring tone creation goes wrong.
ringtone_file=/home/USERNAME/.twinkle/sounds/incoming_call.wav
ringback_file=/home/USERNAME/.twinkle/sounds/outgoing_call.wav
# SCRIPTS
script_incoming_call=/home/USERNAME/.twinkle/scripts/incoming_call.py
script_in_call_answered=
script_in_call_failed=/home/USERNAME/.twinkle/scripts/incoming_call_failed.py
script_outgoing_call=
script_out_call_answered=
script_out_call_failed=
script_local_release=/home/USERNAME/.twinkle/scripts/incoming_call_ended.py
script_remote_release=/home/USERNAME/.twinkle/scripts/incoming_call_ended.py
The file misc/zsh/_khard contains a zsh completion definition for khard.
Install by copying to a directory where zsh searches for completion functions (the $fpath array). If you, for example, put all completion functions into the folder ~/.zsh/completions you must add the following to your zsh main config file:
fpath=( $HOME/.zsh/completions $fpath )
autoload -U compinit
compinit
If you need a console based calendar too, try out khal.