File: open_unix.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20240809.9ab0ca0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,004 kB
  • sloc: sh: 55; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//go:build !windows
// +build !windows

package open

import (
	"context"
	"os/exec"
)

func buildCmd(ctx context.Context, app, path string) *exec.Cmd {
	if _, err := exec.LookPath("open"); err == nil {
		var arg []string
		if app != "" {
			arg = append(arg, "-a", app)
		}
		arg = append(arg, path)
		return exec.CommandContext(ctx, "open", arg...)
	}

	if _, err := exec.LookPath("xdg-open"); err == nil {
		if app == "" {
			return exec.CommandContext(ctx, app, path)
		}
		return exec.CommandContext(ctx, "xdg-open", path)
	}
	return nil
}