aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-10-13 12:52:21 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-16 11:35:24 +0200
commit00daa226f4c4ee6ae86264e069ba56c923f40977 (patch)
tree3ac9f13deb369d7594cf40b08f13c631961900de /commands
parentebfd2a9da3d63390a9d4a0c227b2513a0dac19a4 (diff)
downloadaerc-00daa226f4c4ee6ae86264e069ba56c923f40977.tar.gz
commands: split open-link in separate file
These two commands have virtually zero in common. Move open-link in its own file. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands')
-rw-r--r--commands/msgview/open-link.go41
-rw-r--r--commands/msgview/open.go24
2 files changed, 46 insertions, 19 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
+}
diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 13bd4b11..637fceeb 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -1,11 +1,11 @@
package msgview
import (
+ "errors"
"io"
"mime"
"os"
- "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/widgets"
)
@@ -17,33 +17,19 @@ func init() {
}
func (Open) Aliases() []string {
- return []string{"open", "open-link"}
+ return []string{"open"}
}
func (Open) 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 (Open) Execute(aerc *widgets.Aerc, args []string) error {
mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
- p := mv.SelectedMessagePart()
-
- if args[0] == "open-link" && len(args) > 1 {
- if link := args[1]; link != "" {
- go func() {
- if err := lib.XDGOpen(link); err != nil {
- aerc.PushError("open: " + err.Error())
- }
- }()
- }
- return nil
+ if mv == nil {
+ return errors.New("open only supported selected message parts")
}
+ p := mv.SelectedMessagePart()
mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
extension := ""