check for xdg-open

pull/5/head
Miguel Mota 6 years ago
parent 6352072050
commit 35c4dca299

@ -1,13 +1,12 @@
package cointop
import (
"os/exec"
"github.com/jroimartin/gocui"
"github.com/miguelmota/cointop/pkg/open"
)
func (ct *Cointop) openHelp(g *gocui.Gui, v *gocui.View) error {
exec.Command("open", ct.helpLink()).Output()
open.URL(ct.helpLink())
return nil
}

@ -2,9 +2,9 @@ package cointop
import (
"log"
"os/exec"
"github.com/jroimartin/gocui"
"github.com/miguelmota/cointop/pkg/open"
)
func (ct *Cointop) setKeybinding(key interface{}, callback func(g *gocui.Gui, v *gocui.View) error) {
@ -90,7 +90,7 @@ func (ct *Cointop) refresh(g *gocui.Gui, v *gocui.View) error {
}
func (ct *Cointop) openLink(g *gocui.Gui, v *gocui.View) error {
exec.Command("open", ct.rowLink()).Output()
open.URL(ct.rowLink())
return nil
}

@ -0,0 +1,34 @@
package open
import (
"os/exec"
)
var openCmd string
var possibleCmds = []string{
"xdg-open", // linux
"open", // mac
"start", // windows?
}
func init() {
for i, cmd := range possibleCmds {
out, err := exec.Command("command", "-v", cmd).Output()
if err != nil {
continue
}
bin := string(out)
if bin != "" {
openCmd = possibleCmds[i]
}
}
}
// URL open url
func URL(s string) error {
if openCmd != "" {
exec.Command(openCmd, s).Output()
}
return nil
}
Loading…
Cancel
Save