Find the data root via the XDG config directory

Running the tool from anywhere required either a --root flag or an exported
MONEY_ROOT. Read the data root from $XDG_CONFIG_HOME/money/config.toml
(~/.config/money/config.toml) instead, so it can be configured once.

Resolution order is --root, then $MONEY_ROOT, then the config file, then
~/money. A leading tilde in the config file is expanded, since no shell has
done it for us, and relative paths are made absolute.

The new "money config" subcommand prints the resolved root and which rule
chose it, which is the first thing to check when the tool reads the wrong
directory.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 00:40:59 +02:00
co-authored by Claude Opus 5
parent b0026c5a79
commit cf1753fb0a
4 changed files with 316 additions and 11 deletions
+22 -1
View File
@@ -10,7 +10,7 @@ transfers so they never count as spending.
## Layout
```
~/money/ # the data root ($MONEY_ROOT, or --root)
~/money/ # the data root (see "Where the data root lives")
rules.toml # tag + transfer rules, in order
.money/index.db # SQLite index (rebuildable; safe to delete*)
checking/
@@ -25,6 +25,26 @@ transfers so they never count as spending.
\* Deleting the index loses manual tags and manual transfer marks, which live
only there. Everything else is re-derived from the statements.
## Where the data root lives
Checked in order, first one wins:
1. `--root DIR` on the command line
2. `$MONEY_ROOT`
3. the `root` key in `$XDG_CONFIG_HOME/money/config.toml`, which is
`~/.config/money/config.toml` unless `XDG_CONFIG_HOME` says otherwise
4. `~/money`
So the usual setup is to write the config file once and never pass a flag again:
```toml
# ~/.config/money/config.toml
root = "~/documents/finances"
```
A leading `~` is expanded and relative paths are made absolute. `money config`
prints the resolved root and which of the four rules chose it.
## Usage
```
@@ -38,6 +58,7 @@ money ls --account checking --month 2026-01
money report --month 2026-01 # spending by tag
money accounts # balances
money parsers # available statement parsers
money config # which data root is in use, and why
```
### TUI keys