Here's a simple eclass that pretty much just extracts the XDG stuff from
the gnome2_environment_reset function.

One difference: it creates 3 of the 4 directories under ${HOME} instead
of ${T}, just to mimic the default behavior in the XDG basedir spec a
bit more closely.

Please give a look.
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: xdg-basedir
# @MAINTAINER:
# freedesktop-b...@gentoo.org
# @BLURB: Set up directories according to the XDG Base Directory Specification.
# @EXAMPLE:
# @CODE
# inherit xdg-basedir
#
# src_prepare() {
#       xdg-basedir-setup
# }
# @CODE

# Unset these globally to avoid leaking values from the calling environment.
unset XDG_DATA_HOME XDG_CONFIG_HOME XDG_CACHE_HOME XDG_RUNTIME_DIR

# @FUNCTION: xdg-basedir-setup
# @DESCRIPTION:
# Creates sensible locations for the following environment variables:
# XDG_DATA_HOME
# XDG_CONFIG_HOME
# XDG_CACHE_HOME
# XDG_RUNTIME_DIR
xdg-basedir-setup() {
        export XDG_DATA_HOME="${HOME}/.local/share"
        export XDG_CONFIG_HOME="${HOME}/.config"
        export XDG_CACHE_HOME="${HOME}/.cache"
        export XDG_RUNTIME_DIR="${T}/run"
        mkdir -p "${XDG_DATA_HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" || 
die
        mkdir -p -m 0700 "${XDG_RUNTIME_DIR}" || die
}

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to