mirror of https://github.com/miguelmota/cointop
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
930 B
Go
49 lines
930 B
Go
package open
|
|
|
|
import (
|
|
"log"
|
|
"os/exec"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
var openCmd string
|
|
var possibleCmds = []string{
|
|
"gvfs-open", // gnome linux
|
|
"gnome-open", // gnome linux
|
|
"kde-open", // kde linux
|
|
"exo-open", // xfce linux
|
|
"enlightenment_open", // enlightenment linux
|
|
"xdg-open", // generic linux
|
|
"open", // mac
|
|
"start", // windows
|
|
"cygstart", // windows
|
|
}
|
|
|
|
func init() {
|
|
for _, cmd := range possibleCmds {
|
|
out, err := exec.Command("/usr/bin/command", "-v", cmd).Output()
|
|
if err != nil {
|
|
log.Println("err ", err)
|
|
continue
|
|
}
|
|
|
|
log.Println("out ", string(out))
|
|
bin := strings.TrimSpace(string(out))
|
|
if bin != "" {
|
|
openCmd = bin
|
|
break
|
|
}
|
|
}
|
|
log.Println("cmd ", openCmd)
|
|
time.Sleep(2 * time.Second)
|
|
}
|
|
|
|
// URL open url
|
|
func URL(s string) error {
|
|
if openCmd != "" {
|
|
exec.Command(openCmd, s).Output()
|
|
}
|
|
return nil
|
|
}
|