Skip to content

Commit 6194c0d

Browse files
authored
Merge pull request #404 from anddam/feature-use-xdg-config-directory
Use XDG base directory specification for config files
2 parents e048abf + ba22a66 commit 6194c0d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

tmuxp/cli.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,32 @@ def get_config_dir():
3535
"""
3636
Return tmuxp configuration directory.
3737
38-
Checks for ``TMUXP_CONFIGDIR`` environmental variable.
38+
``TMUXP_CONFIGDIR`` environmental variable has precedence if set. We also
39+
evaluate XDG default directory from XDG_CONFIG_HOME environmental variable
40+
if set or its default. Then the old default ~/.tmuxp is returned for
41+
compatibility.
3942
4043
Returns
4144
-------
4245
str :
4346
absolute path to tmuxp config directory
4447
"""
45-
if 'TMUXP_CONFIGDIR' in os.environ:
46-
return os.path.expanduser(os.environ['TMUXP_CONFIGDIR'])
4748

48-
return os.path.expanduser('~/.tmuxp/')
49+
paths = []
50+
if 'TMUXP_CONFIGDIR' in os.environ:
51+
paths.append(os.environ['TMUXP_CONFIGDIR'])
52+
if 'XDG_CONFIG_HOME' in os.environ:
53+
paths.append(os.environ['XDG_CONFIG_HOME'])
54+
else:
55+
paths.append('~/.config/tmuxp/')
56+
paths.append('~/.tmuxp')
57+
58+
for path in paths:
59+
path = os.path.expanduser(path)
60+
if os.path.isdir(path):
61+
return path
62+
# Return last path as default if none of the previous ones matched
63+
return path
4964

5065

5166
def get_tmuxinator_dir():

0 commit comments

Comments
 (0)