mirror of
https://github.com/miguelmota/cointop
synced 2024-11-10 13:10:26 +00:00
9474610dd6
Former-commit-id: bdaf7e0fdd14654d9b4e52046022ad913b26f722 [formerly bdaf7e0fdd14654d9b4e52046022ad913b26f722 [formerly f756feb3848b7a0c89cda655fe1062f6283affd9 [formerly ff41cbf0f19e7e1d254f72e550adc0b506eb743f]]] Former-commit-id: 03063067ea8bf24017f8d40008d86bc5433edbbf Former-commit-id: 88eae2fe6a9b139d146de6b0b4916b8f25b70b8c [formerly 22a88b2982e228eb77d7fcea9a9038135b4ce3a7] Former-commit-id: 4c28a0bceea32e312e2900ba81a3c95dfb9dddd7
44 lines
835 B
Go
44 lines
835 B
Go
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
|
|
"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
|
|
func URL(s string) error {
|
|
if openCmd != "" {
|
|
exec.Command(openCmd, s).Output()
|
|
}
|
|
return nil
|
|
}
|