aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/main.go b/main.go
index 0f897bd0..707f0444 100644
--- a/main.go
+++ b/main.go
@@ -67,16 +67,13 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
// :q --> :quit
// :ar --> :archive
// :im --> :import-mbox
-func expandAbbreviations(cmd []string, sets []*commands.Commands) []string {
- if len(cmd) == 0 {
- return cmd
- }
- name := strings.TrimLeft(cmd[0], ":")
+func expandAbbreviations(name string, sets []*commands.Commands) string {
+ name = strings.TrimLeft(name, ":")
candidate := ""
for _, set := range sets {
if set.ByName(name) != nil {
// Direct match, return it directly.
- return cmd
+ return name
}
// Check for partial matches.
for _, n := range set.Names() {
@@ -88,7 +85,7 @@ func expandAbbreviations(cmd []string, sets []*commands.Commands) []string {
// matching the input. We can't expand such an
// abbreviation, so return the command as is so
// it can raise an error later.
- return cmd
+ return name
}
// We have a partial match.
candidate = n
@@ -98,19 +95,23 @@ func expandAbbreviations(cmd []string, sets []*commands.Commands) []string {
// name in `cmd`. In that case we replace the name in `cmd` with the
// full name, otherwise we simply return `cmd` as is.
if candidate != "" {
- cmd[0] = candidate
+ name = candidate
}
- return cmd
+ return name
}
func execCommand(
- aerc *widgets.Aerc, ui *libui.UI, cmd []string,
+ aerc *widgets.Aerc, ui *libui.UI, cmdline string,
acct *config.AccountConfig, msg *models.MessageInfo,
) error {
+ name, rest, didCut := strings.Cut(cmdline, " ")
cmds := getCommands(aerc.SelectedTabContent())
- cmd = expandAbbreviations(cmd, cmds)
+ cmdline = expandAbbreviations(name, cmds)
+ if didCut {
+ cmdline += " " + rest
+ }
for i, set := range cmds {
- err := set.ExecuteCommand(aerc, cmd, acct, msg)
+ err := set.ExecuteCommand(aerc, cmdline, acct, msg)
if err != nil {
if errors.As(err, new(commands.NoSuchCommand)) {
if i == len(cmds)-1 {
@@ -243,7 +244,7 @@ func main() {
defer c.Close()
aerc = widgets.NewAerc(c, func(
- cmd []string, acct *config.AccountConfig,
+ cmd string, acct *config.AccountConfig,
msg *models.MessageInfo,
) error {
return execCommand(aerc, ui, cmd, acct, msg)