diff options
Diffstat (limited to 'open.go')
| -rw-r--r-- | open.go | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,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) + } +} |
