docs: document match_dirs for directory-based host selection
Some checks failed
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (push) Has been cancelled
CI / functional (push) Has been cancelled

The match_dirs config option was undocumented. Add a dedicated section
explaining directory-based host selection with examples, and update the
hostname resolution priority list to include match_dirs at step 4.
This commit is contained in:
sid 2026-03-23 13:11:43 -06:00
parent 4669d21dea
commit 2e6575c660

View file

@ -453,13 +453,45 @@ hosts:
token: your_token_here
user: your_username
git_protocol: ssh
match_dirs:
- / # catch-all: use this host when no git remote is detected
codeberg.org:
hostname: codeberg.org
token: another_token
user: another_username
git_protocol: https
match_dirs:
- ~/repos/codeberg # use this host for repos under this directory
```
### Directory-Based Host Selection (`match_dirs`)
When you work with multiple Forgejo/Gitea instances, `fgj` can automatically select the right host based on your current working directory — no `--hostname` flag needed.
Each host entry supports a `match_dirs` list of directory paths. When `fgj` can't determine the host from a git remote, it finds the host whose `match_dirs` entry is the **longest prefix match** for your current directory.
```yaml
hosts:
work.example.com:
# ...
match_dirs:
- ~/work # any repo under ~/work uses this host
personal.example.com:
# ...
match_dirs:
- ~/personal
- ~/side-projects # multiple directories can map to the same host
codeberg.org:
# ...
match_dirs:
- / # catch-all fallback (shortest prefix, lowest priority)
```
- Paths support `~` expansion and symlink resolution
- More specific (longer) paths always win over shorter ones
- Use `/` as a catch-all to override the default `codeberg.org` fallback
- On ties (same prefix length), the host appearing first in the config file wins
### Environment Variables
- `FGJ_HOST`: Override the default instance (auto-detected from git remote if not set)
@ -469,7 +501,8 @@ Hostname is resolved in this priority order:
1. Command-specific flags (e.g., `--hostname`)
2. `FGJ_HOST` environment variable
3. Auto-detected from git remote URL
4. Default to `codeberg.org`
4. `match_dirs` lookup (longest prefix match against current directory)
5. Default to `codeberg.org`
### Command-line Flags