diff --git a/bin/config.py b/bin/config.py index b479408..5ba67e0 100644 --- a/bin/config.py +++ b/bin/config.py @@ -1,10 +1,13 @@ """Configuration management for bin.""" import json +import os from pathlib import Path -CONFIG_PATH = Path.home() / ".config" / "mytoolkit" / "env.json" +_MYTOOLKIT_HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit")) +CONFIG_PATH = _MYTOOLKIT_HOME / "env.json" _LEGACY_PATH = Path(__file__).parent / "config.json" +_LEGACY_CONFIG_DIR = Path.home() / ".config" / "mytoolkit" / "env.json" class Config: @@ -16,10 +19,14 @@ class Config: self._data = self._load() def _migrate_legacy(self) -> None: - """One-shot move of legacy bin/config.json into the user config dir.""" - if _LEGACY_PATH.exists() and not self._config_path.exists(): - self._config_path.parent.mkdir(parents=True, exist_ok=True) + """One-shot move of legacy configs into the user config dir.""" + if self._config_path.exists(): + return + self._config_path.parent.mkdir(parents=True, exist_ok=True) + if _LEGACY_PATH.exists(): _LEGACY_PATH.rename(self._config_path) + elif _LEGACY_CONFIG_DIR.exists(): + _LEGACY_CONFIG_DIR.rename(self._config_path) def _load(self) -> dict: if self._config_path.exists():