Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/custom-commands-spec-clarity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"git-work-grove": patch
---

Improve custom commands spec: fix variable descriptions, clarify absolute paths, document env validation, add env usage example.
32 changes: 23 additions & 9 deletions docs/spec/custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ Same variables as repository/worktree templates:

| Variable | Value |
|---|---|
| `{name}` | Worktree folder name |
| `{branch}` | Git branch (empty if detached HEAD) |
| `{ref}` | Branch or short commit hash (always non-empty) |
| `{name}` | Branch name, or `HEAD` if detached |
| `{branch}` | Full branch name (empty if detached HEAD) |
| `{ref}` | Branch name or short commit hash (always non-empty) |
| `{head}` | Short commit hash (8 chars) |
| `{path}` | Filesystem path |
| `{path}` | Absolute worktree directory path |

### Workspace items (`customCommands.workspace`)

Same variables as worktree workspace templates, plus `{dir}`:

| Variable | Value |
|---|---|
| `{name}` | File name (without `.code-workspace`) |
| `{name}` | File name (without `.code-workspace` extension) |
| `{branch}` | Parent worktree branch (empty if detached HEAD) |
| `{ref}` | Branch or short commit hash (always non-empty) |
| `{ref}` | Branch name or short commit hash (always non-empty) |
| `{head}` | Short commit hash (8 chars) |
| `{path}` | Workspace file path |
| `{dir}` | Parent directory of workspace file path |
| `{path}` | Absolute workspace file path |
| `{dir}` | Absolute parent directory of workspace file |
| `{worktree}` | Parent worktree folder name |

Template syntax (fallback, conditional) is the same as display templates. See [templates.md](../../docs/templates.md) for syntax reference.
Expand Down Expand Up @@ -107,7 +107,7 @@ Same logic as Open in Terminal (see [open-in-terminal.md](open-in-terminal.md)):

- **Spawn failure** (synchronous): try/catch around `spawn()` — shows error via `showErrorMessage`
- **Process error** (asynchronous): `child.on("error")` — shows error with "Show Logs" action
- **Settings validation**: Invalid entries (missing `label`, empty `command`) are skipped with a log message
- **Settings validation**: Invalid entries are skipped with a log message. Checks: `label` must be a non-empty string, `command` must be a non-empty string array, and `env` values (if present) must all be strings
- **Template rendering**: Uses the same `renderTemplate` function as display templates — unknown variables remain as-is

## Examples
Expand Down Expand Up @@ -175,6 +175,20 @@ Common terminal emulators:
}
```

### Using environment variables

```json
{
"git-work-grove.customCommands.directory": [
{
"command": ["open", "-a", "Ghostty", "--args", "--working-directory={path}"],
"env": { "GHOSTTY_TITLE": "{ref}" },
"label": "Open in Ghostty"
}
]
}
```

### Multiple commands

```json
Expand Down
Loading