2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-16 21:25:38 +00:00
cointop/pkg/open/open.go

52 lines
1009 B
Go
Raw Normal View History

//+build !windows
package open
import (
"fmt"
"os/exec"
"strings"
)
var openCmd string
var possibleCmds = []string{
"xdg-open", // generic linux
"gvfs-open", // gnome linux
"gnome-open", // gnome linux
"kde-open", // kde linux
2020-12-04 11:26:15 +00:00
"kde-open5", // kde linux
"exo-open", // xfce linux
"enlightenment_open", // enlightenment linux
"open", // mac
"start", // windows
"cygstart", // windows
}
func init() {
for _, cmd := range possibleCmds {
out, err := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s %s %s", "command", "-v", cmd)).Output()
if err != nil {
continue
}
bin := strings.TrimSpace(string(out))
if bin != "" {
openCmd = bin
break
}
}
}
// URL open url
2020-11-15 22:59:53 +00:00
func URL(url string) error {
if openCmd != "" {
2020-11-15 22:59:53 +00:00
return exec.Command(openCmd, url).Run()
}
return nil
}
// CommandExists returns true if an 'open' command exists
func CommandExists() bool {
return openCmd != ""
}