summary refs log tree commit diff stats
path: root/tinyc/libtcc.h
Commit message (Expand)AuthorAgeFilesLines
* tiny C support; cosmetic improvements for the docsAraq2010-08-281-0/+108
e/attach.go?h=0.6.0&id=fe7230bb9acc5dc9cc8a982a35196dd6796b5360'>^
39307a6 ^
7899d15 ^

bfefaff ^
7899d15 ^










6838c23 ^
7899d15 ^


6838c23 ^
39307a6 ^
bfefaff ^
7899d15 ^

6838c23 ^
39307a6 ^
7899d15 ^


39307a6 ^
7899d15 ^























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




               
                 

              
                                           










                                          
                                  


                                 
                                                                    
                                       
                                          

 
                                                                
                           


                                                          
                                           























                                                                                     
package compose

import (
	"fmt"
	"os"
	"strings"
	"time"

	"git.sr.ht/~sircmpwn/aerc/commands"
	"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 {
	path := strings.Join(args, " ")
	return commands.CompletePath(path)
}

func (Attach) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) == 1 {
		return fmt.Errorf("Usage: :attach <path>")
	}

	path := strings.Join(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
}