mirror of https://github.com/miguelmota/cointop
parent
0859a6cecc
commit
0acb49ca53
@ -1,52 +0,0 @@
|
||||
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 != ""
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
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 != ""
|
||||
}
|
Loading…
Reference in New Issue