From ceec5f8309cf0e625815f233c5bdf8be99a093f9 Mon Sep 17 00:00:00 2001 From: Andrea D'Amore Date: Thu, 5 Jul 2018 11:44:26 +0200 Subject: [PATCH 1/3] Use XDG base directory specification for config files --- tmuxp/cli.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index f2acd60d015..92e0c5ca3b6 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -35,17 +35,31 @@ def get_config_dir(): """ Return tmuxp configuration directory. - Checks for ``TMUXP_CONFIGDIR`` environmental variable. + ``TMUXP_CONFIGDIR`` environmental variable has precedence, then XDG default + directory is checked, either from XDG_CONFIG_HOME environmental variable 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(): From 950e88c772e1e60d0cc380f355d4f6471be1babe Mon Sep 17 00:00:00 2001 From: Ricardo Oliva Date: Mon, 15 Oct 2018 22:55:16 -0400 Subject: [PATCH 2/3] Confirm environment variables are empty before appending them. --- tmuxp/cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 92e0c5ca3b6..91a1ac9b6bb 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -35,9 +35,10 @@ def get_config_dir(): """ Return tmuxp configuration directory. - ``TMUXP_CONFIGDIR`` environmental variable has precedence, then XDG default - directory is checked, either from XDG_CONFIG_HOME environmental variable or - its default, then the old default ~/.tmuxp is returned for compatibility. + ``TMUXP_CONFIGDIR`` environmental variable has precedence if set and not + empty. We also honor XDG default directory, evaluating from XDG_CONFIG_HOME + environmental variable if set and not empty or its default. Then the old + default ~/.tmuxp is returned for compatibility. Returns ------- @@ -46,9 +47,9 @@ def get_config_dir(): """ paths = [] - if 'TMUXP_CONFIGDIR' in os.environ: + if 'TMUXP_CONFIGDIR' in os.environ and os.environ['TMUX_CONFIGDIR']: paths.append(os.environ['TMUXP_CONFIGDIR']) - if 'XDG_CONFIG_HOME' in os.environ: + if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: paths.append(os.environ['XDG_CONFIG_HOME']) else: paths.append('~/.config/tmuxp/') From ba22a66d0037eadaf17a1e5085a06f7015885e2f Mon Sep 17 00:00:00 2001 From: Ricardo Oliva Date: Mon, 15 Oct 2018 23:11:48 -0400 Subject: [PATCH 3/3] Fix check for empty variables as it broke tests and we later check if paths exist as directory. --- tmuxp/cli.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 91a1ac9b6bb..82843b3acee 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -35,10 +35,10 @@ def get_config_dir(): """ Return tmuxp configuration directory. - ``TMUXP_CONFIGDIR`` environmental variable has precedence if set and not - empty. We also honor XDG default directory, evaluating from XDG_CONFIG_HOME - environmental variable if set and not empty or its default. Then the old - default ~/.tmuxp is returned for compatibility. + ``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 ------- @@ -47,9 +47,9 @@ def get_config_dir(): """ paths = [] - if 'TMUXP_CONFIGDIR' in os.environ and os.environ['TMUX_CONFIGDIR']: + if 'TMUXP_CONFIGDIR' in os.environ: paths.append(os.environ['TMUXP_CONFIGDIR']) - if 'XDG_CONFIG_HOME' in os.environ and os.environ['XDG_CONFIG_HOME']: + if 'XDG_CONFIG_HOME' in os.environ: paths.append(os.environ['XDG_CONFIG_HOME']) else: paths.append('~/.config/tmuxp/')