aerc/commands/compose/detach.go
Jeffas 39307a6fa7 Make commands join args with spaces
This patch ensures the following commands join their arguments with
spaces to make it easier to interact with:

- cf
- mkdir
- cd
- attach
- detach
- ct
- copy
- move
- save
2019-09-20 15:06:34 -04:00

51 lines
1,021 B
Go

package compose
import (
"fmt"
"strings"
"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) > 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.PushStatus(fmt.Sprintf("Detached %s", path), 10*time.Second).
Color(tcell.ColorDefault, tcell.ColorGreen)
return nil
}