shell/openBrowser.go

25 lines
461 B
Go
Raw Permalink Normal View History

2024-02-12 15:23:10 -06:00
package shell
import (
"os/exec"
"runtime"
)
// openBrowser opens the specified URL in the default browser of the user.
func OpenBrowser(url string) error {
var cmd string
var args []string
switch runtime.GOOS {
case "windows":
cmd = "cmd"
args = []string{"/c", "start"}
case "darwin":
cmd = "open"
default: // "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}