Skip to content

Fix windows subsystem #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func OpenURL(url string) error {

func runCmd(prog string, args ...string) error {
cmd := exec.Command(prog, args...)
cmd.Stdout = Stdout
cmd.Stderr = Stderr
return cmd.Run()
}
17 changes: 17 additions & 0 deletions browser_linux.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
package browser

import (
"os/exec"
"strings"
)

func hasProgram(name string) bool {
_, err := exec.LookPath(name)
return err == nil
}

func openBrowser(url string) error {
// Windows Subsystem for Linux (bash for Windows) doesn't have xdg-open available
// but you can execute cmd.exe from there; try to identify it
if !hasProgram("xdg-open") && hasProgram("cmd.exe") {
r := strings.NewReplacer("&", "^&")
return runCmd("cmd.exe", "/c", "start", r.Replace(url))
}

return runCmd("xdg-open", url)
}