aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msgview/open-link.go
blob: 257a2fdc7e3ba644a8648da5d397e14e0323d1f2 (plain) (blame)
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
package msgview

import (
	"errors"

	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib"
	"git.sr.ht/~rjarry/aerc/log"
	"git.sr.ht/~rjarry/aerc/widgets"
)

type OpenLink struct{}

func init() {
	register(OpenLink{})
}

func (OpenLink) Aliases() []string {
	return []string{"open-link"}
}

func (OpenLink) Complete(aerc *widgets.Aerc, args []string) []string {
	mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
	if mv != nil {
		if p := mv.SelectedMessagePart(); p != nil {
			return commands.CompletionFromList(aerc, p.Links, args)
		}
	}
	return nil
}

func (OpenLink) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) != 2 {
		return errors.New("Usage: open-link <url>")
	}
	go func() {
		defer log.PanicHandler()
		if err := lib.XDGOpen(args[1]); err != nil {
			aerc.PushError("open-link: " + err.Error())
		}
	}()
	return nil
}