diff options
author | Teddy Wing | 2020-12-19 20:58:39 +0100 |
---|---|---|
committer | Teddy Wing | 2020-12-19 21:03:52 +0100 |
commit | 30d8fa0a2781b6b4cc2b9c0d4301b47c95a13d05 (patch) | |
tree | 8d660a2a061ab6951efc341c03c1cd3c49515500 /browserenv_unix.go | |
parent | efd421e130b4277098e140e37c0e0d76a071540d (diff) | |
download | browserenv-30d8fa0a2781b6b4cc2b9c0d4301b47c95a13d05.tar.bz2 |
Add `BROWSER` support to `OpenURL()`
If the `BROWSER` environment variable is set, open the given URL using
the command specified in the variable.
Run the command in a shell process, either from the `SHELL` environment
variable or `/bin/sh` on Unix OSes. Run it through `cmd` on Windows.
Essentially repurposes my code from
https://github.com/pkg/browser/pull/14.
Diffstat (limited to 'browserenv_unix.go')
-rw-r--r-- | browserenv_unix.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/browserenv_unix.go b/browserenv_unix.go new file mode 100644 index 0000000..e6416f8 --- /dev/null +++ b/browserenv_unix.go @@ -0,0 +1,25 @@ +// +build !windows + +package browserenv + +import ( + "fmt" + "os" +) + +// TODO +func shell() (args []string) { + shell := os.Getenv("SHELL") + + if shell == "" { + shell = "/bin/sh" + } + + return []string{shell, "-c"} +} + +// TODO +func fmtBrowserCommand(browser, url string) string { + // TODO: handle %s in browser command + return fmt.Sprintf("%s '%s'", browser, url) +} |