Skip to content

Commit

Permalink
#66 Ability to open link in cmd and powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
vuon9 committed Nov 10, 2020
1 parent 49dc327 commit 6485927
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cointop/common/open/open.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//+build !windows

package open

import (
Expand Down
52 changes: 52 additions & 0 deletions cointop/common/open/open_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 comments on commit 6485927

Please sign in to comment.