Skip to content

Commit e438247

Browse files
committed
Search for xdg-open in locations outside of PATH
1 parent 7eac2d6 commit e438247

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

cmd/goose/ui.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,21 @@ func openURL(ctx context.Context, rawURL string, gooseParam string) error {
7272
slog.Debug("Executing command", "command", "rundll32.exe url.dll,FileProtocolHandler", "url", rawURL)
7373
cmd = exec.CommandContext(ctx, "rundll32.exe", "url.dll,FileProtocolHandler", rawURL)
7474
default:
75-
// Use xdg-open with full path for Linux and other Unix-like systems
76-
slog.Debug("Executing command", "command", "/usr/bin/xdg-open", "url", rawURL)
77-
cmd = exec.CommandContext(ctx, "/usr/bin/xdg-open", rawURL)
75+
// Use xdg-open for Linux, FreeBSD, and other Unix-like systems
76+
// Check PATH first, then common locations
77+
paths := []string{"xdg-open", "/usr/local/bin/xdg-open", "/usr/bin/xdg-open", "/usr/pkg/bin/xdg-open", "/opt/local/bin/xdg-open"}
78+
var xdgOpenPath string
79+
for _, p := range paths {
80+
if path, err := exec.LookPath(p); err == nil {
81+
xdgOpenPath = path
82+
break
83+
}
84+
}
85+
if xdgOpenPath == "" {
86+
return errors.New("xdg-open not found")
87+
}
88+
slog.Debug("Executing command", "command", xdgOpenPath, "url", rawURL)
89+
cmd = exec.CommandContext(ctx, xdgOpenPath, rawURL)
7890
}
7991

8092
if err := cmd.Start(); err != nil {

0 commit comments

Comments
 (0)