Skip to content

Commit 775868c

Browse files
VdustRclaude
andcommitted
feat: add custom commands for tree view context menu
Allow users to configure external commands (e.g., open in Ghostty, Zed, Terminal.app) triggered from the tree view context menu via two new settings: - customCommands.directory: for worktree/repository items - customCommands.workspace: for workspace file items Each command supports template variables ({name}, {branch}, {ref}, {head}, {path}, {dir}, {worktree}) and optional environment variables. Commands are shown in a QuickPick and spawned as fire-and-forget child processes. Also adds {dir} template variable for workspace items (parent directory). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8698ae6 commit 775868c

17 files changed

+1245
-13
lines changed

.changeset/custom-commands.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"git-work-grove": minor
3+
---
4+
5+
Add custom commands: configure external commands (e.g., open in Ghostty, Zed) triggered from the tree view context menu. Supports template variables for dynamic arguments and environment variables.

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vscode/**
22
.vscode-test/**
3+
.worktrees/**
34
src/**
45
node_modules/**
56
.changeset/**

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Design specs live in `docs/spec/`. These are the **source of truth** for how fea
2525
| `docs/spec/open-behavior.md` | Open modes, URI resolution, click handling |
2626
| `docs/spec/open-in-terminal.md` | CWD resolution, terminal naming, prunable guard |
2727
| `docs/spec/empty-states.md` | Git unavailable, no repository, no worktrees messages |
28+
| `docs/spec/custom-commands.md` | Custom commands: settings, execution, context menu |
2829

2930
## The 4 Fundamental Types
3031

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ If VS Code or GitLens ever ships proper `.code-workspace` support for worktrees,
3636
- **Favorites** — Pin any item (repository, worktree, workspace file) to the top with drag-and-drop reordering
3737
- **Current indicator** — Green icon and badge highlight the currently open item
3838
- **Customizable templates** — Full control over labels and descriptions for all 8 item types
39+
- **Custom Commands** — Define your own context menu commands with template variable support
3940
- **Open in Terminal** — Right-click to open a terminal at any worktree or workspace file location
4041
- **Prune** — Clean up stale worktree records
4142
- **Live updates** — FileSystemWatcher detects worktree changes automatically
@@ -62,6 +63,7 @@ Right-click any item in the tree to access:
6263
| **Open in Current Window** | Opens in the current VS Code window |
6364
| **Open in Terminal** | Opens a terminal at the item's location |
6465
| **Reveal in Finder** | Opens the item's location in your OS file manager |
66+
| **Custom Commands...** | Runs a user-defined command (when configured) |
6567
| **Copy Name** | Copy the item's display name to clipboard |
6668
| **Copy Path** | Copy the item's filesystem path to clipboard |
6769

@@ -113,9 +115,35 @@ Open VS Code Settings (`Cmd+,` / `Ctrl+,`) and search for `git-work-grove`:
113115
| `git-work-grove.openBehavior` | `ask` \| `newWindow` \| `currentWindow` \| `terminal` | `ask` | Default action when opening a workspace |
114116
| `git-work-grove.workspaceFile.include` | `string[]` | `["*.code-workspace"]` | Glob patterns for workspace file scanning |
115117
| `git-work-grove.workspaceFile.exclude` | `string[]` | `[]` | Glob patterns to exclude from scanning |
118+
| `git-work-grove.customCommands.directory` | `array` | `[]` | Custom commands for repository/worktree items |
119+
| `git-work-grove.customCommands.workspace` | `array` | `[]` | Custom commands for workspace file items |
116120
| `git-work-grove.template.*` | `string` | *(varies)* | Display templates (label, description, terminalName) — see [Template Customization](https://github.com/vp-tw/vscode-extension-git-work-grove/blob/main/docs/templates.md) |
117121
| `git-work-grove.favorites` | `string[]` | `[]` | Ordered list of favorited item paths (managed via the UI) |
118122

123+
### Custom Commands
124+
125+
Define custom commands that appear in the tree view context menu. Two settings are available — one for directory items (repository/worktree), one for workspace file items:
126+
127+
```json
128+
{
129+
"git-work-grove.customCommands.directory": [
130+
{
131+
"command": ["npm", "run", "dev"],
132+
"env": { "NODE_ENV": "development" },
133+
"label": "Run Dev Server"
134+
}
135+
],
136+
"git-work-grove.customCommands.workspace": [
137+
{
138+
"command": ["code", "--goto", "{path}"],
139+
"label": "Open in Terminal"
140+
}
141+
]
142+
}
143+
```
144+
145+
Each entry has a `label` (shown in QuickPick), a `command` array (`[bin, ...args]`), and an optional `env` object. Both `command` and `env` values support template variables (`{name}`, `{branch}`, `{ref}`, `{head}`, `{path}` — workspace items also have `{dir}` and `{worktree}`).
146+
119147
### Template Customization
120148

121149
All tree item labels and descriptions are customizable. Templates support variables like `{name}`, `{branch}`, `{ref}`, fallback syntax (`{branch|detached}`), and conditional sections (`{?branch}({branch}){/branch}`).
@@ -145,6 +173,7 @@ These commands appear when right-clicking items in the tree view:
145173
| Open in Current Window | Open in the current VS Code window |
146174
| Open in Terminal | Open a terminal at the item's location |
147175
| Reveal in Finder | Open the item's location in your OS file manager |
176+
| Custom Commands... | Run a user-defined command (when configured) |
148177
| Copy Name | Copy the item's display name to clipboard |
149178
| Copy Path | Copy the item's filesystem path to clipboard |
150179
| Add Favorite | Pin this item to the Favorites section |
@@ -168,6 +197,7 @@ Design documents for contributors and AI-assisted development:
168197
- [Open Behavior](https://github.com/vp-tw/vscode-extension-git-work-grove/blob/main/docs/spec/open-behavior.md) — Open modes, URI resolution, click handling
169198
- [Open in Terminal](https://github.com/vp-tw/vscode-extension-git-work-grove/blob/main/docs/spec/open-in-terminal.md) — CWD resolution, terminal naming, prunable guard
170199
- [Empty States](https://github.com/vp-tw/vscode-extension-git-work-grove/blob/main/docs/spec/empty-states.md) — Git unavailable, no repository, no worktrees messages
200+
- [Custom Commands](https://github.com/vp-tw/vscode-extension-git-work-grove/blob/main/docs/spec/custom-commands.md) — Custom commands: settings, execution, context menu
171201

172202
## Installation
173203

0 commit comments

Comments
 (0)