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>
This commit is contained in:
parent
ebfd2a9da3
commit
00daa226f4
2 changed files with 46 additions and 19 deletions
41
commands/msgview/open-link.go
Normal file
41
commands/msgview/open-link.go
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -1,11 +1,11 @@
|
||||||
package msgview
|
package msgview
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.sr.ht/~rjarry/aerc/commands"
|
|
||||||
"git.sr.ht/~rjarry/aerc/lib"
|
"git.sr.ht/~rjarry/aerc/lib"
|
||||||
"git.sr.ht/~rjarry/aerc/widgets"
|
"git.sr.ht/~rjarry/aerc/widgets"
|
||||||
)
|
)
|
||||||
|
@ -17,34 +17,20 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Open) Aliases() []string {
|
func (Open) Aliases() []string {
|
||||||
return []string{"open", "open-link"}
|
return []string{"open"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Open) Complete(aerc *widgets.Aerc, args []string) []string {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Open) Execute(aerc *widgets.Aerc, args []string) error {
|
func (Open) Execute(aerc *widgets.Aerc, args []string) error {
|
||||||
mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
|
mv := aerc.SelectedTabContent().(*widgets.MessageViewer)
|
||||||
|
if mv == nil {
|
||||||
|
return errors.New("open only supported selected message parts")
|
||||||
|
}
|
||||||
p := mv.SelectedMessagePart()
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
|
mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
|
||||||
extension := ""
|
extension := ""
|
||||||
mimeType := ""
|
mimeType := ""
|
||||||
|
|
Loading…
Reference in a new issue