00daa226f4
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>
41 lines
812 B
Go
41 lines
812 B
Go
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
|
|
}
|