From 00daa226f4c4ee6ae86264e069ba56c923f40977 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 13 Oct 2022 12:52:21 +0200 Subject: 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 Tested-by: Inwit Acked-by: Moritz Poldrack --- commands/msgview/open.go | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'commands/msgview/open.go') 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 := "" -- cgit