Skip to content
0

khard

Khard is an address book for the Unix command line. It can read, create, modify and delete vCard address book entries. Khard only works with a local store of vCard files. It is intended to be used in conjunction with other programs like an email client, text editor, vdir synchronizer or VOIP client.

Installation

  • macOS
  • iTerm2
bash
brew install khard

Configuration

# example configuration file for khard version > 0.14.0
# place it under ~/.config/khard/khard.conf
# This file is parsed by the configobj library. The syntax is described at
# https://configobj.readthedocs.io/en/latest/configobj.html#the-config-file-format

[addressbooks]
[[family]]
path = ~/.contacts/family/
[[friends]]
path = ~/.contacts/friends/
[[work]]
path = ~/.contacts/work/
type = discover

[general]
debug = no
default_action = list
# These are either strings or comma seperated lists
# editor = vim, -i, NONE
editor = nvim
merge_editor = vimdiff


[contact table]
# display names by first or last name: first_name / last_name / formatted_name
display = first_name
# group by address book: yes / no
group_by_addressbook = no
# reverse table ordering: yes / no
reverse = no
# append nicknames to name column: yes / no
show_nicknames = no
# show uid table column: yes / no
show_uids = yes
# show kind table column: yes / no
show_kinds = no
# sort by first or last name: first_name / last_name / formatted_name
sort = last_name
# localize dates: yes / no
localize_dates = yes
# set a comma separated list of preferred phone number types in descending priority
# or nothing for non-filtered alphabetical order
preferred_phone_number_type = pref, cell, home
# set a comma separated list of preferred email address types in descending priority
# or nothing for non-filtered alphabetical order
preferred_email_address_type = pref, work, home

[vcard]
# extend contacts with your own private objects
# these objects are stored with a leading "X-" before the object name in the vcard files
# every object label may only contain letters, digits and the - character
# example:
#   private_objects = Jabber, Skype, Twitter
# default: ,  (the empty list)
private_objects = Jabber, Skype, Twitter
# preferred vcard version: 3.0 / 4.0
preferred_version = 3.0
# Look into source vcf files to speed up search queries: yes / no
search_in_source_files = no
# skip unparsable vcard files: yes / no
skip_unparsable = no

Command line usage

Show contacts

  • khard list
  • khard list -a addressbook1,addressbook2
  • khard show
  • khard show name_of_contact

Create contact

  • khard new
  • khard new [-a "address book name"]

Edit contacts

  • khard edit [-a addr_name] [search terms [search terms ...]]
  • khard email -a work

Address book directories need to be created in advance, before you could reference them in the ~/.config/khard/khard.conf file.

Custom address templates

  • khard show steven
  • khard postaddress steven

Both commands print the address of Steven, suitable for printing onto an envelope. But the current output format of the address only works nicely for some European countries, not for the US, not for the UK.

US address

ymal
   Address:
       home:
           Box:
           Extended:
           Street: 567 E Evelyn Ave, Apt 1234
           Code: 94041
           City: Mountain View
           Region: CA
           Country: USA

Current khard output format (non American standard):

bash
{Street}
{Extended}
{Code} {City}
{Region}, {Country}
bash
Address
    home:
        567 E Evelyn Ave
        Apt 1234
        94041 Mountain View
        CA, USA

Standard US address format:

bash
{Street}
{City}
{Region} {Code}, {Country}
bash
Address
    home:
        567 E Evelyn Ave
        Apt 1234
        Mountain View
        CA 94041, USA

UK address

Example 1

ymal
Address:
    home:
        Box:
        Extended:
        Street: Unit 5, Hounslow Business Park, Alice Way
        Code: TW3 3UD
        City: Middlesex
        Region:
        Country: United Kingdom

Current khard output format (non British standard):

bash
Address
    home:
        Unit 5, Hounslow Business Park, Alice Way
        TW3 3UD Middlesex
        United Kingdom

Standard UK address format:

bash
{Street}
{City}, {Code}
{Country}
bash
Address
    home:
        Unit 5, Hounslow Business Park, Alice Way
        Middlesex, TW3 3UD
        United Kingdom

There is not an established solution to this format problem, as custom address templates are currently unavailable for the users.

Workaround

  • khard show --format=yaml steven

--format possible choices: pretty, yaml, vcard, with default pretty. With the yaml format, it is easier to read as compared to the pretty format, which looks really odd for an standard American address.

yaml
Address :
    home :
        Box      :
        Extended :
        Street   :
        Code     :
        City     :
        Region   :
        Country  :
最近更新