Skip to content

Commit b3caa5d

Browse files
authored
Merge pull request #180 from Maxteabag/xdg-config-dir
Default to XDG config dir with migration from ~/.sqlit
2 parents 5197b28 + 10e70a4 commit b3caa5d

File tree

17 files changed

+261
-28
lines changed

17 files changed

+261
-28
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@ Autocomplete triggers automatically in INSERT mode. Use `Tab` to accept.
233233

234234
## Configuration
235235

236-
Connections and settings are stored in `~/.sqlit/`.
236+
Connections and settings are stored in `$XDG_CONFIG_HOME/sqlit/` (default: `~/.config/sqlit/`). Override the location by setting `SQLIT_CONFIG_DIR`.
237+
238+
If an older install left files in `~/.sqlit/`, they are moved to the new location automatically on first run.
237239

238240
## FAQ
239241

240242
### How are sensitive credentials stored?
241243

242-
Connection details are stored in `~/.sqlit/connections.json`, but passwords are stored in your OS keyring when available (macOS Keychain, Windows Credential Locker, Linux Secret Service).
244+
Connection details are stored in `connections.json` inside the config directory, but passwords are stored in your OS keyring when available (macOS Keychain, Windows Credential Locker, Linux Secret Service).
243245

244246
### How does sqlit compare to Harlequin, Lazysql, etc.?
245247

sqlit/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def main() -> int:
372372
parser.add_argument(
373373
"--settings",
374374
metavar="PATH",
375-
help="Path to settings JSON file (overrides ~/.sqlit/settings.json)",
375+
help="Path to settings JSON file (overrides the one in the sqlit config directory)",
376376
)
377377
parser.add_argument(
378378
"--theme",

sqlit/domains/connections/cli/commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _maybe_prompt_plaintext_credentials(services: AppServices) -> bool:
6363
if not sys.stdin.isatty():
6464
return False
6565

66-
answer = input("Keyring isn't available. Save passwords as plaintext in ~/.sqlit/? [y/N]: ").strip().lower()
66+
answer = input("Keyring isn't available. Save passwords as plaintext in the sqlit config directory? [y/N]: ").strip().lower()
6767
allow = answer in {"y", "yes"}
6868
settings[ALLOW_PLAINTEXT_CREDENTIALS_SETTING] = allow
6969
services.settings_store.save_all(settings)

sqlit/domains/connections/discovery/cloud/aws/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
from __future__ import annotations
44

55
import json
6-
import os
76
import time
87
from dataclasses import dataclass, field
9-
from pathlib import Path
108
from typing import TYPE_CHECKING
119

10+
from sqlit.shared.core.store import CONFIG_DIR
11+
1212
if TYPE_CHECKING:
1313
from .provider import RegionResources
1414

1515
# Cache configuration
1616
AWS_CACHE_TTL_SECONDS = 300 # 5 minutes
17-
AWS_CACHE_FILE = Path(os.path.expanduser("~/.config/sqlit/aws_cache.json"))
17+
AWS_CACHE_FILE = CONFIG_DIR / "aws_cache.json"
1818

1919

2020
@dataclass

sqlit/domains/connections/discovery/cloud/azure/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from __future__ import annotations
44

55
import json
6-
import os
76
import time
87
from dataclasses import dataclass
9-
from pathlib import Path
8+
9+
from sqlit.shared.core.store import CONFIG_DIR
1010

1111
from .models import AzureSqlServer, AzureSubscription
1212

1313
# Cache configuration
1414
AZURE_CACHE_TTL_SECONDS = 300 # 5 minutes
15-
AZURE_CACHE_FILE = Path(os.path.expanduser("~/.config/sqlit/azure_cache.json"))
15+
AZURE_CACHE_FILE = CONFIG_DIR / "azure_cache.json"
1616

1717

1818
@dataclass

sqlit/domains/connections/discovery/cloud/gcp/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
from __future__ import annotations
44

55
import json
6-
import os
76
import time
87
from dataclasses import dataclass, field
9-
from pathlib import Path
108
from typing import TYPE_CHECKING
119

10+
from sqlit.shared.core.store import CONFIG_DIR
11+
1212
if TYPE_CHECKING:
1313
from .provider import GCPCloudSQLInstance
1414

1515
# Cache configuration
1616
GCP_CACHE_TTL_SECONDS = 300 # 5 minutes
17-
GCP_CACHE_FILE = Path(os.path.expanduser("~/.config/sqlit/gcp_cache.json"))
17+
GCP_CACHE_FILE = CONFIG_DIR / "gcp_cache.json"
1818

1919

2020
@dataclass

sqlit/domains/connections/store/connections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class ConnectionStore(JSONFileStore):
1616
"""Store for managing saved database connections.
1717
18-
Connections are stored as a JSON object (versioned) in ~/.sqlit/connections.json.
18+
Connections are stored as connections.json in the sqlit config directory (versioned).
1919
Passwords are stored separately in the OS keyring via CredentialsService.
2020
"""
2121

sqlit/domains/connections/ui/mixins/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def on_confirm(confirmed: bool | None) -> None:
597597
self.services.credentials_service = build_credentials_service(self.services.settings_store)
598598
self.services.connection_store.set_credentials_service(self.services.credentials_service)
599599
do_save(config, original_name)
600-
self.notify("Saved passwords as plaintext in ~/.sqlit/ (0600)", severity="warning")
600+
self.notify("Saved passwords as plaintext in the sqlit config directory (0600)", severity="warning")
601601
return
602602

603603
settings2[ALLOW_PLAINTEXT_CREDENTIALS_SETTING] = False
@@ -612,7 +612,7 @@ def on_confirm(confirmed: bool | None) -> None:
612612
self.push_screen(
613613
ConfirmScreen(
614614
"Keyring isn't available",
615-
"Save passwords as plaintext in ~/.sqlit/ (protected directory)?",
615+
"Save passwords as plaintext in the sqlit config directory (protected directory)?",
616616
yes_label="Yes",
617617
no_label="No",
618618
),

sqlit/domains/query/store/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def from_dict(cls, data: dict) -> QueryHistoryEntry:
4444
class HistoryStore(JSONFileStore):
4545
"""Store for managing query history.
4646
47-
History is stored as a JSON array in ~/.sqlit/query_history.json
47+
History is stored as query_history.json in the sqlit config directory.
4848
Each entry includes query text, timestamp, and connection name.
4949
"""
5050

sqlit/domains/query/store/starred.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class StarredStore(JSONFileStore):
99
"""Store for managing starred queries.
1010
11-
Starred queries are stored as a JSON object in ~/.sqlit/starred_queries.json
11+
Starred queries are stored as starred_queries.json in the sqlit config directory.
1212
Structure: { "connection_name": ["query1", "query2", ...] }
1313
1414
Starred queries persist independently of history - they are never auto-deleted

0 commit comments

Comments
 (0)