summaryrefslogtreecommitdiff
path: root/open.go
blob: 93be28b51e39cb6d62cebceb566cb87787cefb5d (plain)
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
package main

import (
	"log"
	"os/exec"
	"runtime"
)

// Open opens a file (or a directory or url), just as if the user had double-clicked the file's icon.
// It uses the default application, as determined by the OS.
func openInBrowser(path string) {
	var args []string
	switch runtime.GOOS {
	case "darwin":
		args = []string{"open", path}
	case "windows":
		args = []string{"cmd", "/c", "start", path}
	default:
		args = []string{"xdg-open", path}
	}
	cmd := exec.Command(args[0], args[1:]...)
	err := cmd.Run()
	if err != nil {
		log.Println("u4.Open:", err)
	}
}