refactor: migrate all config paths to ~/.mytoolkit with MYTOOLKIT_HOME support

This commit is contained in:
Zhengshou Lai
2026-06-04 00:52:25 +08:00
parent 3a47e6963d
commit 2d2ff45fca
3 changed files with 10 additions and 6 deletions
+4 -4
View File
@@ -50,11 +50,11 @@ mytoolkit templates register /path/to/templates
mytoolkit templates list # lists each template with its absolute path mytoolkit templates list # lists each template with its absolute path
``` ```
Registry is stored at `~/.config/mytoolkit/templates.json`. Registry is stored at `~/.mytoolkit/templates.json` (or `$MYTOOLKIT_HOME/templates.json`).
## User config ## User config
All user-level config lives under `~/.config/mytoolkit/`: All user-level config lives under `~/.mytoolkit/` (override with `$MYTOOLKIT_HOME`):
| File | Owner | Purpose | | File | Owner | Purpose |
|------|-------|---------| |------|-------|---------|
@@ -74,7 +74,7 @@ mytoolkit env export # print MYCLI_FOO=... export statements
eval "$(mytoolkit env export)" # load into current shell eval "$(mytoolkit env export)" # load into current shell
``` ```
Legacy `bin/config.json` (in the source dir) is auto-migrated to `~/.config/mytoolkit/env.json` on first run after upgrade. Legacy `bin/config.json` (in the source dir) is auto-migrated to `~/.mytoolkit/env.json` on first run after upgrade.
## Uninstall ## Uninstall
@@ -84,4 +84,4 @@ mytoolkit uninstall
make uninstall make uninstall
``` ```
User config under `~/.config/mytoolkit/` is left in place. User config under `~/.mytoolkit/` is left in place.
+3 -1
View File
@@ -3,6 +3,7 @@
import base64 import base64
import imaplib import imaplib
import json import json
import os
import re import re
import smtplib import smtplib
from datetime import datetime from datetime import datetime
@@ -16,7 +17,8 @@ import click
from bin.utils import handle_errors from bin.utils import handle_errors
CONFIG_PATH = Path.home() / ".config" / "mytoolkit" / "mail.json" _HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit"))
CONFIG_PATH = _HOME / "mail.json"
def load_config(): def load_config():
+3 -1
View File
@@ -1,11 +1,13 @@
"""External templates registry for md→pdf / md→docx conversion.""" """External templates registry for md→pdf / md→docx conversion."""
import json import json
import os
from pathlib import Path from pathlib import Path
import click import click
CONFIG_PATH = Path.home() / ".config" / "mytoolkit" / "templates.json" _HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit"))
CONFIG_PATH = _HOME / "templates.json"
def _read() -> dict: def _read() -> dict: