Skip to content

Commit ceec5f8

Browse files
committed
Use XDG base directory specification for config files
1 parent e048abf commit ceec5f8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

tmuxp/cli.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,31 @@ 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, then XDG default
39+
directory is checked, either from XDG_CONFIG_HOME environmental variable or
40+
its default, then the old default ~/.tmuxp is returned for compatibility.
3941
4042
Returns
4143
-------
4244
str :
4345
absolute path to tmuxp config directory
4446
"""
45-
if 'TMUXP_CONFIGDIR' in os.environ:
46-
return os.path.expanduser(os.environ['TMUXP_CONFIGDIR'])
4747

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

5064

5165
def get_tmuxinator_dir():

0 commit comments

Comments
 (0)