Skip to content

Use XDG base directory specification for config files #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,32 @@ def get_config_dir():
"""
Return tmuxp configuration directory.

Checks for ``TMUXP_CONFIGDIR`` environmental variable.
``TMUXP_CONFIGDIR`` environmental variable has precedence if set. We also
evaluate XDG default directory from XDG_CONFIG_HOME environmental variable
if set or its default. Then the old default ~/.tmuxp is returned for
compatibility.

Returns
-------
str :
absolute path to tmuxp config directory
"""
if 'TMUXP_CONFIGDIR' in os.environ:
return os.path.expanduser(os.environ['TMUXP_CONFIGDIR'])

return os.path.expanduser('~/.tmuxp/')
paths = []
if 'TMUXP_CONFIGDIR' in os.environ:
paths.append(os.environ['TMUXP_CONFIGDIR'])
if 'XDG_CONFIG_HOME' in os.environ:
paths.append(os.environ['XDG_CONFIG_HOME'])
else:
paths.append('~/.config/tmuxp/')
paths.append('~/.tmuxp')

for path in paths:
path = os.path.expanduser(path)
if os.path.isdir(path):
return path
# Return last path as default if none of the previous ones matched
return path


def get_tmuxinator_dir():
Expand Down