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.
cointop/cointop/common/open/open_win.go

53 lines
763 B
Go

package open
import (
"os/exec"
)
var openCmd string
var possibleCmds = []string{
"Start-Process", // windows
}
var possibleShells = []string{
"powershell.exe",
"explorer.exe",
}
var mainShell string
func init() {
for _, sh := range possibleShells {
shell, err := exec.LookPath(sh)
if err != nil {
continue
}
mainShell = shell
break
}
for _, cmd := range possibleCmds {
err := exec.Command(mainShell, "Get-Command", cmd).Run()
if err != nil {
continue
}
openCmd = cmd
break
}
}
// URL open url
func URL(s string) error {
if openCmd != "" {
return exec.Command(mainShell, openCmd, s).Run()
}
return nil
}
// CommandExists returns true if an 'open' command exists
func CommandExists() bool {
return openCmd != ""
}