File: copy-link.go

package info (click to toggle)
aerc 0.21.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,900 kB
  • sloc: ansic: 1,181; python: 1,000; sh: 553; awk: 360; makefile: 23
file content (53 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
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
package msgview

import (
	"net/url"

	"git.sr.ht/~rjarry/aerc/app"
	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/ui"
)

type CopyLink struct {
	Url *url.URL `opt:"url" action:"ParseUrl" complete:"CompleteUrl"`
}

func init() {
	commands.Register(CopyLink{})
}

func (CopyLink) Description() string {
	return "Copy the specified URL to the system clipboard."
}

func (CopyLink) Context() commands.CommandContext {
	return commands.MESSAGE_VIEWER
}

func (CopyLink) Aliases() []string {
	return []string{"copy-link"}
}

func (*CopyLink) CompleteUrl(arg string) []string {
	mv := app.SelectedTabContent().(*app.MessageViewer)
	if mv != nil {
		if p := mv.SelectedMessagePart(); p != nil {
			return commands.FilterList(p.Links, arg, nil)
		}
	}
	return nil
}

func (o *CopyLink) ParseUrl(arg string) error {
	u, err := url.Parse(arg)
	if err != nil {
		return err
	}
	o.Url = u
	return nil
}

func (o CopyLink) Execute(args []string) error {
	ui.PushClipboard(o.Url.String())
	return nil
}