Commands returns a list of possible commands to use to open a url.
()
| 16 | |
| 17 | // Commands returns a list of possible commands to use to open a url. |
| 18 | func Commands() [][]string { |
| 19 | var cmds [][]string |
| 20 | if exe := os.Getenv("BROWSER"); exe != "" { |
| 21 | cmds = append(cmds, []string{exe}) |
| 22 | } |
| 23 | switch runtime.GOOS { |
| 24 | case "darwin": |
| 25 | cmds = append(cmds, []string{"/usr/bin/open"}) |
| 26 | case "windows": |
| 27 | cmds = append(cmds, []string{"cmd", "/c", "start"}) |
| 28 | default: |
| 29 | if os.Getenv("DISPLAY") != "" { |
| 30 | // xdg-open is only for use in a desktop environment. |
| 31 | cmds = append(cmds, []string{"xdg-open"}) |
| 32 | } |
| 33 | } |
| 34 | cmds = append(cmds, |
| 35 | []string{"chrome"}, |
| 36 | []string{"google-chrome"}, |
| 37 | []string{"chromium"}, |
| 38 | []string{"firefox"}, |
| 39 | ) |
| 40 | return cmds |
| 41 | } |
| 42 | |
| 43 | // Open tries to open url in a browser and reports whether it succeeded. |
| 44 | func Open(url string) bool { |