From 3ab86f0cbd029a80b33ff88a86e7720efb4f5fc0 Mon Sep 17 00:00:00 2001 From: malc Date: Wed, 20 Aug 2014 22:30:33 +0400 Subject: [PATCH] XDG Thanks to Mark Oteiza. --- config.ml | 12 ++++++++---- misc/llppac | 14 +++++++++----- utils.ml | 6 ++++++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/config.ml b/config.ml index 0405bd1..d324088 100644 --- a/config.ml +++ b/config.ml @@ -1456,10 +1456,14 @@ let do_load f ic = let defconfpath = let dir = - try - let dir = Filename.concat home ".config" in - if Sys.is_directory dir then dir else home - with _ -> home + let xdgconfdir = Utils.getenvwithdef "XDG_CONFIG_HOME" E.s in + if xdgconfdir == E.s + then + try + let dir = Filename.concat home ".config" in + if Sys.is_directory dir then dir else home + with _ -> home + else xdgconfdir in Filename.concat dir "llpp.conf" ;; diff --git a/misc/llppac b/misc/llppac index 5200b98..0af4d96 100755 --- a/misc/llppac +++ b/misc/llppac @@ -1,15 +1,20 @@ #!/bin/sh set -e -CACHEDIR=$HOME/.cache/llpp -caspsuf= -type= - die() { echo "$1" >&2 exit 1 } +test -n "$XDG_CACHE_HOME" \ + && cachedir="$XDG_CACHE_HOME" || cachedir="$HOME/.cache" + +CACHEDIR=$cachedir/llpp +test -d "$CACHEDIR" || die "cache directory '$CACHEDIR' does not exist" + +caspsuf= +type= + executable_p() { command -v "$1" >/dev/null 2>&1 } @@ -36,7 +41,6 @@ EOF trap 'test -n "$casp" && rm -f "$casp"' 0 -test -d "$CACHEDIR" || die "cache directory '$CACHEDIR' does not exist" while getopts m:t:f opt; do case $opt in m) mime=$OPTARG;; diff --git a/utils.ml b/utils.ml index d63d647..30673c0 100644 --- a/utils.ml +++ b/utils.ml @@ -176,3 +176,9 @@ module Ne = struct with exn -> Exn exn ;; end;; + +let getenvwithdef name def = + try + Sys.getenv name + with Not_found -> def +;; -- 2.11.4.GIT