Add :attach command for compose
Allow users to add attachments to emails in the Compose view. Syntax is :attach <path>, where path is a valid file. Attachments will show up in the pre-send review screen.
This commit is contained in:
parent
fe7230bb9a
commit
7899d15d60
3 changed files with 190 additions and 17 deletions
commands/compose
56
commands/compose/attach.go
Normal file
56
commands/compose/attach.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package compose
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.sr.ht/~sircmpwn/aerc/widgets"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
type Attach struct{}
|
||||
|
||||
func init() {
|
||||
register(Attach{})
|
||||
}
|
||||
|
||||
func (_ Attach) Aliases() []string {
|
||||
return []string{"attach"}
|
||||
}
|
||||
|
||||
func (_ Attach) Complete(aerc *widgets.Aerc, args []string) []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ Attach) Execute(aerc *widgets.Aerc, args []string) error {
|
||||
if len(args) != 2 {
|
||||
return fmt.Errorf("Usage: :attach <path>")
|
||||
}
|
||||
|
||||
path := args[1]
|
||||
|
||||
path, err := homedir.Expand(path)
|
||||
if err != nil {
|
||||
aerc.PushError(" " + err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
pathinfo, err := os.Stat(path)
|
||||
if err != nil {
|
||||
aerc.PushError(" " + err.Error())
|
||||
return err
|
||||
} else if pathinfo.IsDir() {
|
||||
aerc.PushError("Attachment must be a file, not a directory")
|
||||
return nil
|
||||
}
|
||||
|
||||
composer, _ := aerc.SelectedTab().(*widgets.Composer)
|
||||
composer.AddAttachment(path)
|
||||
|
||||
aerc.PushStatus(fmt.Sprintf("Attached %s", pathinfo.Name()), 10*time.Second).
|
||||
Color(tcell.ColorDefault, tcell.ColorGreen)
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue