Skip to content

Commit ab5c1ea

Browse files
committed
Explain config in the README
1 parent 313e9a6 commit ab5c1ea

File tree

1 file changed

+98
-3
lines changed

1 file changed

+98
-3
lines changed

README.md

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cargo install --path .
2828
## Usage
2929

3030
```bash
31-
# Jump to a worktree. Branch must exist.
31+
# Jump to a worktree.
3232
cd "$(terris feature-a)"
3333

3434
# List worktrees
@@ -43,17 +43,112 @@ terris --rm feature-a
4343

4444

4545
## How it works
46-
- `terris <branch>` creates the worktree (branch must exist) and prints the path every time.
46+
- `terris <branch>` creates the worktree and prints the path every time.
4747
- `terris` lists worktrees for the current repository.
4848
- `terris --all` lists all worktrees, including ones without branches.
4949
- If the branch exists, it is used directly.
50-
- If the branch does not exist, the command fails with an error.
50+
- If the branch does not exist, behavior depends on your terris config.
5151
- Default path is `~/.terris-worktrees/<repo-name>/<branch>-<random-key>`.
5252

5353
## Notes
5454
- Works from any directory inside a git repo.
5555
- The tool shells out to `git`, so `git` must be installed and available in `PATH`.
5656

57+
## Configuration
58+
59+
terris reads configuration from these files, in this order:
60+
61+
1. `~/.terris/terris.toml` for user-wide defaults
62+
2. `<git-root>/.terris.toml` for project-specific overrides
63+
64+
If both files exist, terris merges them and the project-local file overrides the global one. If neither exists, built-in defaults are used.
65+
66+
Create a global config:
67+
68+
```bash
69+
mkdir -p ~/.terris
70+
$EDITOR ~/.terris/terris.toml
71+
```
72+
73+
Create a project-local config:
74+
75+
```bash
76+
$EDITOR .terris.toml
77+
```
78+
79+
Example:
80+
81+
```toml
82+
[worktrees]
83+
base_dir = "~/src/worktrees"
84+
use_random_suffix = true
85+
suffix_length = 8
86+
87+
[behavior]
88+
on_missing_branch = "fetch, create"
89+
auto_prune = true
90+
91+
[display]
92+
show_head = true
93+
```
94+
95+
### Available settings
96+
97+
#### `[worktrees]`
98+
99+
- `base_dir`: Base directory for new worktrees. Supports `~`. Default: `~/.terris-worktrees`
100+
- `use_random_suffix`: Whether to append a random suffix to worktree directory names. Default: `true`
101+
- `suffix_length`: Length of the random suffix when `use_random_suffix = true`. Default: `8`. Valid range: `1..=64`
102+
103+
With defaults, terris creates worktrees under:
104+
105+
```text
106+
~/.terris-worktrees/<repo-name>/<branch>-<random-key>
107+
```
108+
109+
If `use_random_suffix = false`, the path becomes:
110+
111+
```text
112+
~/.terris-worktrees/<repo-name>/<branch>
113+
```
114+
115+
#### `[behavior]`
116+
117+
- `on_missing_branch`: What terris should do when the requested branch does not exist locally. Default: `"error"`
118+
- `auto_prune`: Run `git worktree prune` before listing worktrees. Default: `false`
119+
120+
`on_missing_branch` accepts a comma-separated list of actions tried in order:
121+
122+
- `error`: Fail immediately. This cannot be combined with other actions.
123+
- `fetch`: Run `git fetch origin <branch>` and use the remote branch if found.
124+
- `create`: Create a new local branch from the current `HEAD`.
125+
126+
Examples:
127+
128+
```toml
129+
[behavior]
130+
on_missing_branch = "error"
131+
```
132+
133+
```toml
134+
[behavior]
135+
on_missing_branch = "fetch"
136+
```
137+
138+
```toml
139+
[behavior]
140+
on_missing_branch = "fetch, create"
141+
```
142+
143+
```toml
144+
[behavior]
145+
on_missing_branch = "create"
146+
```
147+
148+
#### `[display]`
149+
150+
- `show_head`: Show the short `HEAD` commit hash as an extra column when listing worktrees. Default: `false`
151+
57152
## Shell completion
58153

59154
Generate a completion script and source it in your shell:

0 commit comments

Comments
 (0)