aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msgview/open-link.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/msgview/open-link.go')
-rw-r--r--commands/msgview/open-link.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/commands/msgview/open-link.go b/commands/msgview/open-link.go
new file mode 100644
index 00000000..d19dfae0
--- /dev/null
+++ b/commands/msgview/open-link.go
@@ -0,0 +1,41 @@
+package msgview
+
+import (
+ "errors"
+
+ "git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/lib"
+ "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() {
+ if err := lib.XDGOpen(args[1]); err != nil {
+ aerc.PushError("open-link: " + err.Error())
+ }
+ }()
+ return nil
+}