2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-05 00:00:14 +00:00
cointop/pkg/open/open_windows.go

51 lines
847 B
Go
Raw Normal View History

2020-11-15 22:59:53 +00:00
package open
import (
"os/exec"
)
var windowsOpenCmd string
var windowsPossibleCmds = []string{
"Start-Process",
}
var windowsPossibleExecs = []string{
"powershell.exe",
"explorer.exe",
}
var windowsOpenExec string
func init() {
for _, exe := range windowsPossibleExecs {
execPath, err := exec.LookPath(exe)
if err != nil {
continue
}
windowsOpenExec = execPath
break
}
for _, cmd := range windowsPossibleCmds {
err := exec.Command(windowsOpenExec, "Get-Command", cmd).Run()
if err != nil {
continue
}
windowsOpenCmd = cmd
break
}
}
// URL open url
func URL(url string) error {
if windowsOpenCmd != "" {
return exec.Command(windowsOpenExec, windowsOpenCmd, url).Run()
}
return nil
}
// CommandExists returns true if an 'open' command exists
func CommandExists() bool {
return windowsOpenCmd != ""
}