diff --git a/README.rst b/README.rst index 803716c..a28bf3d 100644 --- a/README.rst +++ b/README.rst @@ -21,12 +21,14 @@ Installation and usage ====================== If you already have it installed and want to quickly configure it, copy the -``example.cfg`` to ``~/.vdirsyncer/config`` and edit it. +``example.cfg`` to ``~/.vdirsyncer/config`` [1]_ and edit it. If that method doesn't work for you or you want a deeper understanding of what you just did, check out `the tutorial `_. +.. [1] The configuration file can also be placed in ``$XDG_CONFIG_HOME/vdirsyncer/config`` (normally ``~/.config/vdirsyncer/config``) for XDG-Basedir spec compliance. + Donations ========= diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 584feb5..aae6a5f 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -33,9 +33,14 @@ Configuration - Take a look at the :doc:`problems` page if anything doesn't work like planned. -By default, *vdirsyncer* looks for its configuration file at -``~/.vdirsyncer/config``. You can use the ``VDIRSYNCER_CONFIG`` environment -variable to change this path. +By default, *vdirsyncer* looks for its configuration file in the following +locations: + +- The file pointed to by the ``VDIRSYNCER_CONFIG`` environment variable. +- ``~/.vdirsyncer/config``. +- ``$XDG_CONFIG_HOME/vdirsyncer/config``, which is normally + ``~/.config/vdirsyncer/config``. This is XDG-Basedir compliant, and should + help keep your ``$HOME`` clean. The config file should start with a :ref:`general section `, where the only required parameter is ``status_path``. The following is a diff --git a/vdirsyncer/cli.py b/vdirsyncer/cli.py index 3d93fb5..07a6b6f 100644 --- a/vdirsyncer/cli.py +++ b/vdirsyncer/cli.py @@ -278,6 +278,10 @@ def _create_app(): if 'config' not in ctx.obj: fname = expand_path(os.environ.get('VDIRSYNCER_CONFIG', '~/.vdirsyncer/config')) + if not os.path.exists(fname): + xdg_config_dir = os.environ.get('XDG_CONFIG_HOME', + expand_path('~/.config/')) + fname = os.path.join(xdg_config_dir, 'vdirsyncer/config') try: ctx.obj['config'] = load_config(fname) except Exception as e: