| 1 |
//go:build !windows |
| 2 |
// +build !windows |
| 3 |
|
| 4 |
package open |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"os/exec" |
| 9 |
) |
| 10 |
|
| 11 |
func buildCmd(ctx context.Context, app, path string) *exec.Cmd { |
| 12 |
if _, err := exec.LookPath("open"); err == nil { |
| 13 |
var arg []string |
| 14 |
if app != "" { |
| 15 |
arg = append(arg, "-a", app) |
| 16 |
} |
| 17 |
arg = append(arg, path) |
| 18 |
return exec.CommandContext(ctx, "open", arg...) |
| 19 |
} |
| 20 |
if app != "" { |
| 21 |
return exec.CommandContext(ctx, app, path) |
| 22 |
} |
| 23 |
if _, err := exec.LookPath("xdg-open"); err == nil { |
| 24 |
return exec.CommandContext(ctx, "xdg-open", path) |
| 25 |
} |
| 26 |
return nil |
| 27 |
} |