Skip to content

Commit 2d60206

Browse files
committed
Add WSL fallback for Linux
1 parent fa77765 commit 2d60206

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

browser_linux.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
package browser
22

3-
import "os/exec"
3+
import (
4+
"errors"
5+
"os/exec"
6+
)
47

58
func openBrowser(url string) error {
6-
return runCmd("xdg-open", url)
9+
browserPath, err := lookPath("xdg-open", "wslview")
10+
if err != nil {
11+
return err
12+
}
13+
return runCmd(browserPath, url)
14+
}
15+
16+
func lookPath(cmdName, fallbackName string) (string, error) {
17+
cmdPath, err := exec.LookPath(cmdName)
18+
if errors.Is(err, exec.ErrNotFound) {
19+
if wslPath, err := exec.LookPath(fallbackName); err == nil {
20+
return wslPath, nil
21+
}
22+
}
23+
return cmdPath, err
724
}
825

926
func setFlags(cmd *exec.Cmd) {}

0 commit comments

Comments
 (0)