Skip to content

Commit 7781caa

Browse files
committed
use xdg-open on linux
1 parent 7a61221 commit 7781caa

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

cmd/browser.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cmd
22

33
import (
44
"errors"
5+
"os/exec"
6+
"runtime"
57

68
"github.com/pkg/browser"
79
)
@@ -10,7 +12,24 @@ import (
1012
var ErrMockBrowser = errors.New("mock browser error")
1113

1214
// OpenURLInBrowser is exported for testing
13-
var OpenURLInBrowser = browser.OpenURL
15+
var OpenURLInBrowser = openURLInBrowser
16+
17+
func openURLInBrowser(url string) error {
18+
// On Linux, use xdg-open with output redirection to suppress messages
19+
if runtime.GOOS == "linux" {
20+
return openWithXdgOpen(url)
21+
}
22+
// For other platforms, use the default browser library
23+
return browser.OpenURL(url)
24+
}
25+
26+
func openWithXdgOpen(url string) error {
27+
cmd := exec.Command("xdg-open", url)
28+
// Redirect stdout and stderr to /dev/null to suppress output
29+
cmd.Stdout = nil
30+
cmd.Stderr = nil
31+
return cmd.Start()
32+
}
1433

1534
func openURLInBrowserFunc(url string) error {
1635
return OpenURLInBrowser(url)

0 commit comments

Comments
 (0)