summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-07-08 08:20:55 -0500
committeradamdottv <[email protected]>2025-07-08 08:20:55 -0500
commit0da83ae67eac6fa3703a40c81b11c49cb6a30ca0 (patch)
tree53eae5d53adcdffc69122d431ffc7a375e184183
parent662d022a4859ee1c004133559ee42c5f7044dda7 (diff)
downloadopencode-0da83ae67eac6fa3703a40c81b11c49cb6a30ca0.tar.gz
opencode-0da83ae67eac6fa3703a40c81b11c49cb6a30ca0.zip
feat(tui): command aliases
-rw-r--r--packages/tui/internal/commands/command.go43
-rw-r--r--packages/tui/internal/completions/commands.go21
-rw-r--r--packages/tui/internal/components/commands/commands.go8
3 files changed, 45 insertions, 27 deletions
diff --git a/packages/tui/internal/commands/command.go b/packages/tui/internal/commands/command.go
index 10b0d7e27..791f74759 100644
--- a/packages/tui/internal/commands/command.go
+++ b/packages/tui/internal/commands/command.go
@@ -29,7 +29,7 @@ type Command struct {
Name CommandName
Description string
Keybindings []Keybinding
- Trigger string
+ Trigger []string
}
func (c Command) Keys() []string {
@@ -40,6 +40,21 @@ func (c Command) Keys() []string {
return keys
}
+func (c Command) HasTrigger() bool {
+ return len(c.Trigger) > 0
+}
+
+func (c Command) PrimaryTrigger() string {
+ if len(c.Trigger) > 0 {
+ return c.Trigger[0]
+ }
+ return ""
+}
+
+func (c Command) MatchesTrigger(trigger string) bool {
+ return slices.Contains(c.Trigger, trigger)
+}
+
type CommandRegistry map[CommandName]Command
func (r CommandRegistry) Sorted() []Command {
@@ -135,37 +150,37 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
Name: AppHelpCommand,
Description: "show help",
Keybindings: parseBindings("<leader>h"),
- Trigger: "help",
+ Trigger: []string{"help"},
},
{
Name: EditorOpenCommand,
Description: "open editor",
Keybindings: parseBindings("<leader>e"),
- Trigger: "editor",
+ Trigger: []string{"editor"},
},
{
Name: SessionNewCommand,
Description: "new session",
Keybindings: parseBindings("<leader>n"),
- Trigger: "new",
+ Trigger: []string{"new", "clear"},
},
{
Name: SessionListCommand,
Description: "list sessions",
Keybindings: parseBindings("<leader>l"),
- Trigger: "sessions",
+ Trigger: []string{"sessions", "resume", "continue"},
},
{
Name: SessionShareCommand,
Description: "share session",
Keybindings: parseBindings("<leader>s"),
- Trigger: "share",
+ Trigger: []string{"share"},
},
{
Name: SessionUnshareCommand,
Description: "unshare session",
Keybindings: parseBindings("<leader>u"),
- Trigger: "unshare",
+ Trigger: []string{"unshare"},
},
{
Name: SessionInterruptCommand,
@@ -176,31 +191,31 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
Name: SessionCompactCommand,
Description: "compact the session",
Keybindings: parseBindings("<leader>c"),
- Trigger: "compact",
+ Trigger: []string{"compact", "summarize"},
},
{
Name: ToolDetailsCommand,
Description: "toggle tool details",
Keybindings: parseBindings("<leader>d"),
- Trigger: "details",
+ Trigger: []string{"details"},
},
{
Name: ModelListCommand,
Description: "list models",
Keybindings: parseBindings("<leader>m"),
- Trigger: "models",
+ Trigger: []string{"models"},
},
{
Name: ThemeListCommand,
Description: "list themes",
Keybindings: parseBindings("<leader>t"),
- Trigger: "themes",
+ Trigger: []string{"themes"},
},
{
Name: FileListCommand,
Description: "list files",
Keybindings: parseBindings("<leader>f"),
- Trigger: "files",
+ Trigger: []string{"files"},
},
{
Name: FileCloseCommand,
@@ -221,7 +236,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
Name: ProjectInitCommand,
Description: "create/update AGENTS.md",
Keybindings: parseBindings("<leader>i"),
- Trigger: "init",
+ Trigger: []string{"init"},
},
{
Name: InputClearCommand,
@@ -302,7 +317,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
Name: AppExitCommand,
Description: "exit the app",
Keybindings: parseBindings("ctrl+c", "<leader>q"),
- Trigger: "exit",
+ Trigger: []string{"exit", "quit"},
},
}
registry := make(CommandRegistry)
diff --git a/packages/tui/internal/completions/commands.go b/packages/tui/internal/completions/commands.go
index c73923e8e..3a5dc3bb1 100644
--- a/packages/tui/internal/completions/commands.go
+++ b/packages/tui/internal/completions/commands.go
@@ -31,7 +31,7 @@ func (c *CommandCompletionProvider) GetEmptyMessage() string {
func getCommandCompletionItem(cmd commands.Command, space int, t theme.Theme) dialog.CompletionItemI {
spacer := strings.Repeat(" ", space)
- title := " /" + cmd.Trigger + styles.NewStyle().Foreground(t.TextMuted()).Render(spacer+cmd.Description)
+ title := " /" + cmd.PrimaryTrigger() + styles.NewStyle().Foreground(t.TextMuted()).Render(spacer+cmd.Description)
value := string(cmd.Name)
return dialog.NewCompletionItem(dialog.CompletionItem{
Title: title,
@@ -45,8 +45,8 @@ func (c *CommandCompletionProvider) GetChildEntries(query string) ([]dialog.Comp
space := 1
for _, cmd := range c.app.Commands {
- if lipgloss.Width(cmd.Trigger) > space {
- space = lipgloss.Width(cmd.Trigger)
+ if cmd.HasTrigger() && lipgloss.Width(cmd.PrimaryTrigger()) > space {
+ space = lipgloss.Width(cmd.PrimaryTrigger())
}
}
space += 2
@@ -56,10 +56,10 @@ func (c *CommandCompletionProvider) GetChildEntries(query string) ([]dialog.Comp
// If no query, return all commands
items := []dialog.CompletionItemI{}
for _, cmd := range sorted {
- if cmd.Trigger == "" {
+ if !cmd.HasTrigger() {
continue
}
- space := space - lipgloss.Width(cmd.Trigger)
+ space := space - lipgloss.Width(cmd.PrimaryTrigger())
items = append(items, getCommandCompletionItem(cmd, space, t))
}
return items, nil
@@ -70,12 +70,15 @@ func (c *CommandCompletionProvider) GetChildEntries(query string) ([]dialog.Comp
commandMap := make(map[string]dialog.CompletionItemI)
for _, cmd := range sorted {
- if cmd.Trigger == "" {
+ if !cmd.HasTrigger() {
continue
}
- space := space - lipgloss.Width(cmd.Trigger)
- commandNames = append(commandNames, cmd.Trigger)
- commandMap[cmd.Trigger] = getCommandCompletionItem(cmd, space, t)
+ space := space - lipgloss.Width(cmd.PrimaryTrigger())
+ // Add all triggers as searchable options
+ for _, trigger := range cmd.Trigger {
+ commandNames = append(commandNames, trigger)
+ commandMap[trigger] = getCommandCompletionItem(cmd, space, t)
+ }
}
// Find fuzzy matches
diff --git a/packages/tui/internal/components/commands/commands.go b/packages/tui/internal/components/commands/commands.go
index f3080b38f..7f293230c 100644
--- a/packages/tui/internal/components/commands/commands.go
+++ b/packages/tui/internal/components/commands/commands.go
@@ -56,8 +56,8 @@ func (c *commandsComponent) View() string {
var untriggeredCommands []commands.Command
for _, cmd := range c.app.Commands.Sorted() {
- if c.showAll || cmd.Trigger != "" {
- if cmd.Trigger != "" {
+ if c.showAll || cmd.HasTrigger() {
+ if cmd.HasTrigger() {
triggeredCommands = append(triggeredCommands, cmd)
} else if c.showAll {
untriggeredCommands = append(untriggeredCommands, cmd)
@@ -97,8 +97,8 @@ func (c *commandsComponent) View() string {
for _, cmd := range commandsToShow {
trigger := ""
- if cmd.Trigger != "" {
- trigger = "/" + cmd.Trigger
+ if cmd.HasTrigger() {
+ trigger = "/" + cmd.PrimaryTrigger()
} else {
trigger = string(cmd.Name)
}