This repository was archived by the owner on Sep 18, 2025. It is now read-only.
Repository navigation
feat: custom commands #133
Merged
kujtimiihoxha
merged 12 commits into
opencode-ai:main
from
mark3labs:implement-custom-commands
May 9, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
29a3cc7
Implement custom commands
ezynda3 540ea76
Add User: prefix
ezynda3 5257916
Reuse var
ezynda3 b4a6883
Merge branch 'opencode-ai:main' into implement-custom-commands
ezynda3 ab4aa9f
Check if the agent is busy and if so report a warning
ezynda3 0a46a89
Update README
ezynda3 db11b72
fix typo
ezynda3 4e489d7
Implement user and project scoped custom commands
ezynda3 93262a3
Allow for $ARGUMENTS
ezynda3 0585b4d
UI tweaks
ezynda3 0adbce9
Update internal/tui/components/dialog/arguments.go
ezynda3 0020a97
Also search in $HOME/.opencode/commands
ezynda3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| package dialog | ||
|
|
||
| import ( | ||
| "github.com/charmbracelet/bubbles/key" | ||
| "github.com/charmbracelet/bubbles/textinput" | ||
| tea "github.com/charmbracelet/bubbletea" | ||
| "github.com/charmbracelet/lipgloss" | ||
|
|
||
| "github.com/opencode-ai/opencode/internal/tui/styles" | ||
| "github.com/opencode-ai/opencode/internal/tui/theme" | ||
| "github.com/opencode-ai/opencode/internal/tui/util" | ||
| ) | ||
|
|
||
| // ArgumentsDialogCmp is a component that asks the user for command arguments. | ||
| type ArgumentsDialogCmp struct { | ||
| width, height int | ||
| textInput textinput.Model | ||
| keys argumentsDialogKeyMap | ||
| commandID string | ||
| content string | ||
| } | ||
|
|
||
| // NewArgumentsDialogCmp creates a new ArgumentsDialogCmp. | ||
| func NewArgumentsDialogCmp(commandID, content string) ArgumentsDialogCmp { | ||
| t := theme.CurrentTheme() | ||
| ti := textinput.New() | ||
| ti.Placeholder = "Enter arguments..." | ||
| ti.Focus() | ||
| ti.Width = 40 | ||
| ti.Prompt = "" | ||
| ti.PlaceholderStyle = ti.PlaceholderStyle.Background(t.Background()) | ||
| ti.PromptStyle = ti.PromptStyle.Background(t.Background()) | ||
| ti.TextStyle = ti.TextStyle.Background(t.Background()) | ||
|
|
||
| return ArgumentsDialogCmp{ | ||
| textInput: ti, | ||
| keys: argumentsDialogKeyMap{}, | ||
| commandID: commandID, | ||
| content: content, | ||
| } | ||
| } | ||
|
|
||
| type argumentsDialogKeyMap struct { | ||
| Enter key.Binding | ||
| Escape key.Binding | ||
| } | ||
|
|
||
| // ShortHelp implements key.Map. | ||
| func (k argumentsDialogKeyMap) ShortHelp() []key.Binding { | ||
| return []key.Binding{ | ||
| key.NewBinding( | ||
| key.WithKeys("enter"), | ||
| key.WithHelp("enter", "confirm"), | ||
| ), | ||
| key.NewBinding( | ||
| key.WithKeys("esc"), | ||
| key.WithHelp("esc", "cancel"), | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| // FullHelp implements key.Map. | ||
| func (k argumentsDialogKeyMap) FullHelp() [][]key.Binding { | ||
| return [][]key.Binding{k.ShortHelp()} | ||
| } | ||
|
|
||
| // Init implements tea.Model. | ||
| func (m ArgumentsDialogCmp) Init() tea.Cmd { | ||
| return tea.Batch( | ||
| textinput.Blink, | ||
| m.textInput.Focus(), | ||
| ) | ||
| } | ||
|
|
||
| // Update implements tea.Model. | ||
| func (m ArgumentsDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | ||
| var cmd tea.Cmd | ||
| var cmds []tea.Cmd | ||
|
|
||
| switch msg := msg.(type) { | ||
| case tea.KeyMsg: | ||
| switch { | ||
| case key.Matches(msg, key.NewBinding(key.WithKeys("esc"))): | ||
| return m, util.CmdHandler(CloseArgumentsDialogMsg{}) | ||
| case key.Matches(msg, key.NewBinding(key.WithKeys("enter"))): | ||
| return m, util.CmdHandler(CloseArgumentsDialogMsg{ | ||
| Submit: true, | ||
| CommandID: m.commandID, | ||
| Content: m.content, | ||
| Arguments: m.textInput.Value(), | ||
| }) | ||
| } | ||
| case tea.WindowSizeMsg: | ||
| m.width = msg.Width | ||
| m.height = msg.Height | ||
| } | ||
|
|
||
| m.textInput, cmd = m.textInput.Update(msg) | ||
| cmds = append(cmds, cmd) | ||
|
|
||
| return m, tea.Batch(cmds...) | ||
| } | ||
|
|
||
| // View implements tea.Model. | ||
| func (m ArgumentsDialogCmp) View() string { | ||
| t := theme.CurrentTheme() | ||
| baseStyle := styles.BaseStyle() | ||
|
|
||
| // Calculate width needed for content | ||
| maxWidth := 60 // Width for explanation text | ||
|
|
||
| title := baseStyle. | ||
| Foreground(t.Primary()). | ||
| Bold(true). | ||
| Width(maxWidth). | ||
| Padding(0, 1). | ||
| Render("Command Arguments") | ||
|
|
||
| explanation := baseStyle. | ||
| Foreground(t.Text()). | ||
| Width(maxWidth). | ||
| Padding(0, 1). | ||
| Render("This command requires arguments. Please enter the text to replace $ARGUMENTS with:") | ||
|
|
||
| inputField := baseStyle. | ||
| Foreground(t.Text()). | ||
| Width(maxWidth). | ||
| Padding(1, 1). | ||
| Render(m.textInput.View()) | ||
|
|
||
| maxWidth = min(maxWidth, m.width-10) | ||
|
|
||
| content := lipgloss.JoinVertical( | ||
| lipgloss.Left, | ||
| title, | ||
| explanation, | ||
| inputField, | ||
| ) | ||
|
|
||
| return baseStyle.Padding(1, 2). | ||
| Border(lipgloss.RoundedBorder()). | ||
| BorderBackground(t.Background()). | ||
| BorderForeground(t.TextMuted()). | ||
| Background(t.Background()). | ||
| Width(lipgloss.Width(content) + 4). | ||
| Render(content) | ||
| } | ||
|
|
||
| // SetSize sets the size of the component. | ||
| func (m *ArgumentsDialogCmp) SetSize(width, height int) { | ||
| m.width = width | ||
| m.height = height | ||
| } | ||
|
|
||
| // Bindings implements layout.Bindings. | ||
| func (m ArgumentsDialogCmp) Bindings() []key.Binding { | ||
| return m.keys.ShortHelp() | ||
| } | ||
|
|
||
| // CloseArgumentsDialogMsg is a message that is sent when the arguments dialog is closed. | ||
| type CloseArgumentsDialogMsg struct { | ||
| Submit bool | ||
| CommandID string | ||
| Content string | ||
| Arguments string | ||
| } | ||
|
|
||
| // ShowArgumentsDialogMsg is a message that is sent to show the arguments dialog. | ||
| type ShowArgumentsDialogMsg struct { | ||
| CommandID string | ||
| Content string | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.