2019-07-27 16:38:53 +02:00
|
|
|
package compose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-09-20 18:16:29 +02:00
|
|
|
"strings"
|
2020-05-28 16:32:32 +02:00
|
|
|
"time"
|
2019-07-27 16:38:53 +02:00
|
|
|
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
2020-05-28 16:32:42 +02:00
|
|
|
"github.com/gdamore/tcell"
|
2019-07-27 16:38:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Detach struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(Detach{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Detach) Aliases() []string {
|
2019-07-27 16:38:53 +02:00
|
|
|
return []string{"detach"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Detach) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-07-27 16:38:53 +02:00
|
|
|
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
|
|
|
return composer.GetAttachments()
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Detach) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-07-27 16:38:53 +02:00
|
|
|
var path string
|
|
|
|
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
|
|
|
|
2019-09-20 18:16:29 +02:00
|
|
|
if len(args) > 1 {
|
|
|
|
path = strings.Join(args[1:], " ")
|
2019-07-27 16:38:53 +02:00
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
2020-05-28 16:32:42 +02:00
|
|
|
aerc.PushStatus(fmt.Sprintf("Detached %s", path), 10*time.Second).
|
|
|
|
Color(tcell.ColorDefault, tcell.ColorGreen)
|
2019-07-27 16:38:53 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|