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.
This commit is contained in:
parent
a669233614
commit
0ee7d30187
3 changed files with 79 additions and 0 deletions
commands/compose
55
commands/compose/detach.go
Normal file
55
commands/compose/detach.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue