docs: document match_dirs for directory-based host selection
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:
parent
4669d21dea
commit
2e6575c660
1 changed files with 34 additions and 1 deletions
35
README.md
35
README.md
|
|
@ -453,13 +453,45 @@ hosts:
|
||||||
token: your_token_here
|
token: your_token_here
|
||||||
user: your_username
|
user: your_username
|
||||||
git_protocol: ssh
|
git_protocol: ssh
|
||||||
|
match_dirs:
|
||||||
|
- / # catch-all: use this host when no git remote is detected
|
||||||
codeberg.org:
|
codeberg.org:
|
||||||
hostname: codeberg.org
|
hostname: codeberg.org
|
||||||
token: another_token
|
token: another_token
|
||||||
user: another_username
|
user: another_username
|
||||||
git_protocol: https
|
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
|
### Environment Variables
|
||||||
|
|
||||||
- `FGJ_HOST`: Override the default instance (auto-detected from git remote if not set)
|
- `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`)
|
1. Command-specific flags (e.g., `--hostname`)
|
||||||
2. `FGJ_HOST` environment variable
|
2. `FGJ_HOST` environment variable
|
||||||
3. Auto-detected from git remote URL
|
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
|
### Command-line Flags
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue