diff options
| author | Teddy Wing | 2019-06-23 18:45:47 +0200 |
|---|---|---|
| committer | Teddy Wing | 2019-06-23 20:42:45 +0200 |
| commit | 884bf54a000924670c0a0d86f4c10c2278ff2daf (patch) | |
| tree | dc6b3cdf195fb9274c79dfb8e7476c7cd5495e34 /browser_unix.go | |
| parent | 0a3d74bf9ce488f035cf5bc36f753a711bc74334 (diff) | |
| download | browser-884bf54a000924670c0a0d86f4c10c2278ff2daf.tar.bz2 | |
Add support for the BROWSER environment variablesupport-for-BROWSER-environment-variable
Allow user-defined URL-opening commands via the BROWSER environment
variable. This enables using a non-default browser, or changing the
browser for a single command.
For example, on Mac:
$ export BROWSER='open -a Firefox'
Windows:
> setx BROWSER "start iexplore"
In UNIX environments, the command is run through `$SHELL -c`, or
`/bin/sh` if `$SHELL` is not set. On Windows, it uses `cmd /c`.
Ensure that URLs are properly quoted between UNIX and Windows
environments in `fmtBrowserCmd()`.
Diffstat (limited to 'browser_unix.go')
| -rw-r--r-- | browser_unix.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/browser_unix.go b/browser_unix.go new file mode 100644 index 0000000..30d57db --- /dev/null +++ b/browser_unix.go @@ -0,0 +1,22 @@ +// +build !windows + +package browser + +import ( + "fmt" + "os" +) + +func shell() (shell, flag string) { + shell = os.Getenv("SHELL") + + if shell == "" { + shell = "/bin/sh" + } + + return shell, "-c" +} + +func fmtBrowserCmd(browser, url string) string { + return fmt.Sprintf("%s '%s'", browser, url) +} |
