aboutsummaryrefslogtreecommitdiff
path: root/commands/compose
diff options
context:
space:
mode:
authorGalen Abell <galen@galenabell.com>2019-07-27 10:38:53 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-27 12:37:55 -0400
commit0ee7d30187920751c6e79facbd87ebce86d62ec9 (patch)
tree3b56110366eb95e40049fef851747f42ff53e4c9 /commands/compose
parenta669233614d3b4134baabd3325cb64e8f0f2cdeb (diff)
Add :detach command
Add a command for removing attachments from a composed message. Syntax is :detach [path], with path being an optional argument specifying the path of one existing attachment. If no path is specified, the first attachment is removed.
Diffstat (limited to 'commands/compose')
-rw-r--r--commands/compose/detach.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/commands/compose/detach.go b/commands/compose/detach.go
new file mode 100644
index 0000000..e700ab6
--- /dev/null
+++ b/commands/compose/detach.go
@@ -0,0 +1,55 @@
+package compose
+
+import (
+ "fmt"
+ "time"
+
+ "git.sr.ht/~sircmpwn/aerc/widgets"
+ "github.com/gdamore/tcell"
+)
+
+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) > 2 {
+ return fmt.Errorf("Usage: :detach [path]")
+ }
+
+ if len(args) == 2 {
+ path = 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.PushStatus(fmt.Sprintf("Detached %s", path), 10*time.Second).
+ Color(tcell.ColorDefault, tcell.ColorGreen)
+
+ return nil
+}