2018-04-06 02:15:21 +00:00
|
|
|
package open
|
|
|
|
|
|
|
|
import (
|
2018-04-19 06:32:57 +00:00
|
|
|
"fmt"
|
2018-04-06 02:15:21 +00:00
|
|
|
"os/exec"
|
2018-04-18 03:53:52 +00:00
|
|
|
"strings"
|
2018-04-06 02:15:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var openCmd string
|
|
|
|
var possibleCmds = []string{
|
2018-04-19 06:33:53 +00:00
|
|
|
"xdg-open", // generic linux
|
2018-04-19 06:22:17 +00:00
|
|
|
"gvfs-open", // gnome linux
|
|
|
|
"gnome-open", // gnome linux
|
|
|
|
"kde-open", // kde linux
|
|
|
|
"exo-open", // xfce linux
|
|
|
|
"enlightenment_open", // enlightenment linux
|
|
|
|
"open", // mac
|
|
|
|
"start", // windows
|
|
|
|
"cygstart", // windows
|
2018-04-06 02:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-04-19 06:28:19 +00:00
|
|
|
for _, cmd := range possibleCmds {
|
2018-04-19 06:32:57 +00:00
|
|
|
out, err := exec.Command("/bin/bash", "-c", fmt.Sprintf("%s %s %s", "command", "-v", cmd)).Output()
|
2018-04-06 02:15:21 +00:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2018-04-18 03:53:52 +00:00
|
|
|
bin := strings.TrimSpace(string(out))
|
2018-04-06 02:15:21 +00:00
|
|
|
if bin != "" {
|
2018-04-19 06:28:19 +00:00
|
|
|
openCmd = bin
|
2018-04-19 06:26:38 +00:00
|
|
|
break
|
2018-04-06 02:15:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// URL open url
|
|
|
|
func URL(s string) error {
|
|
|
|
if openCmd != "" {
|
|
|
|
exec.Command(openCmd, s).Output()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|