aboutsummaryrefslogtreecommitdiffstats
path: root/src/__main__.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-04-02 20:14:43 +0200
committerMattias Andrée <maandree@operamail.com>2015-04-02 20:14:43 +0200
commitebdfa7ecc86e983f8730d0113c89538c9b9d83c4 (patch)
treed76719e77221f1c862ee36cc276d6852a3f2f216 /src/__main__.py
parentderp (diff)
downloadxpybar-ebdfa7ecc86e983f8730d0113c89538c9b9d83c4.tar.gz
xpybar-ebdfa7ecc86e983f8730d0113c89538c9b9d83c4.tar.bz2
xpybar-ebdfa7ecc86e983f8730d0113c89538c9b9d83c4.tar.xz
add support for XDG_CONFIG_DIRS
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rwxr-xr-xsrc/__main__.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/__main__.py b/src/__main__.py
index e4e00bf..722e453 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -541,21 +541,26 @@ config_file = a(parser.opts['--configurations'])
## Load extension and configurations via xpybarrc
if config_file is None:
- # TODO add support for $XDG_CONFIG_DIRS
- files = ('$XDG_CONFIG_HOME/%/%rc', '$HOME/.config/%/%rc', '$HOME/.%rc',
- '$~/.config/%/%rc', '$~/.%rc', '/etc/%rc')
+ dirs = os.environ['XDG_CONFIG_DIRS'].split(':') if 'XDG_CONFIG_DIRS' in os.environ else []
+ files = ['$XDG_CONFIG_DIRS/%rc'] * len(dirs)
+ files = ['$XDG_CONFIG_HOME/%/%rc', '$HOME/.config/%/%rc', '$HOME/.%rc',
+ '$~/.config/%/%rc', '$~/.%rc'] + files + ['/etc/%rc']
+ home = pwd.getpwuid(os.getuid()).pw_dir.replace('$', '\0')
for file in files:
file = file.replace('%', 'xpybar')
- for arg in ('XDG_CONFIG_HOME', 'HOME'):
+ for arg in ('XDG_CONFIG_HOME', 'XDG_CONFIG_DIRS', 'HOME', '~'):
if '$' + arg in file:
- if arg in os.environ:
+ if arg == 'XDG_CONFIG_DIRS':
+ dir, dirs = dirs[0].replace('$', '\0'), dirs[1:]
+ file = file.replace('$' + arg, dir)
+ elif arg == '~':
+ file = file.replace('$' + arg, home)
+ elif arg in os.environ:
file = file.replace('$' + arg, os.environ[arg].replace('$', '\0'))
else:
file = None
break
if file is not None:
- if file.startswith('$~'):
- file = pwd.getpwuid(os.getuid()).pw_dir + file[2:]
file = file.replace('\0', '$')
if os.path.exists(file):
config_file = file