aerc/commands/compose/detach.go
Robin Jarry 0d645bcebd go.mod: change base git url
I'm not sure what are the implications but it seems required.

Link: https://github.com/golang/go/issues/20883
Signed-off-by: Robin Jarry <robin@jarry.cc>
2021-11-05 10:21:45 +01:00

49 lines
921 B
Go

package compose
import (
"fmt"
"strings"
"git.sr.ht/~rjarry/aerc/widgets"
)
type Detach struct{}
func init() {
register(Detach{})
}
func (Detach) Aliases() []string {
return []string{"detach"}
}
func (Detach) Complete(aerc *widgets.Aerc, args []string) []string {
composer, _ := aerc.SelectedTab().(*widgets.Composer)
return composer.GetAttachments()
}
func (Detach) Execute(aerc *widgets.Aerc, args []string) error {
var path string
composer, _ := aerc.SelectedTab().(*widgets.Composer)
if len(args) > 1 {
path = strings.Join(args[1:], " ")
} else {
// if no attachment is specified, delete the first in the list
atts := composer.GetAttachments()
if len(atts) > 0 {
path = atts[0]
} else {
return fmt.Errorf("No attachments to delete")
}
}
if err := composer.DeleteAttachment(path); err != nil {
return err
}
aerc.PushSuccess(fmt.Sprintf("Detached %s", path))
return nil
}