aboutsummaryrefslogtreecommitdiffstats
path: root/browserenv.go
AgeCommit message (Collapse)Author
2020-12-20Add package-level documentationTeddy Wing
2020-12-20Set `pkg/browser`'s `Stderr` and `Stdout` to oursTeddy Wing
We need to connect our `Stderr` and `Stdout` to those in `github.com/pkg/browser` so that custom writers get linked correctly in the underlying library. Previously, customising these writers only worked for the command specified in the `BROWSER` environment variable, not when `BROWSER` was unset.
2020-12-20Add function and variable documentationTeddy Wing
2020-12-20Remove handled TODOsTeddy Wing
2020-12-20Support multiple colon-separated commands in `BROWSER`Teddy Wing
After reading the `urlview` man page, I learned that it supports multiple commands in the `BROWSER` environment variable separated by colons. Read over the source to see what `urlview` does: https://github.com/sigpipe/urlview/blob/08767aa863cd27d1755ba0aff65b8cc1a0c1446a/urlview.c#L617-L630 It tries each command from left to right until one of them exits with a `0` exit code. Use the same logic here.
2020-12-20Connect `Stdout` and `Stderr` to browser commandTeddy Wing
Use the global `Stdout` and `Stderr` variables when running the command specified by `BROWSER`.
2020-12-20Move browser command formatting to a new `fmtBrowserCommand()`Teddy Wing
Not to be confused with the previous `fmtBrowserCommand()` function, this one handles all formatting including `%s`, shell escaping, etc.
2020-12-20Rename `escapeBrowserCommand()` to `shellEscapeCommand()`Teddy Wing
Didn't like `escapeBrowserCommand()` either, since we're escaping the URL not the rest of the command.
2020-12-20Rename `fmtBrowserCommand()` to `escapeBrowserCommand()`Teddy Wing
Formatting the browser command will incorporate more steps, not just this one, so rename it to be more specific about what it's doing. I want to use the other name for a different function.
2020-12-20Escape single quotes in URLTeddy Wing
On Unix, we escape the URL argument by surrounding it with single quotes. This fails if the URL contains single quotes. It also fails if the `BROWSER` command contains `%s` not surrounded by single quotes. Fix this by escaping the single quotes. We might also want to look into passing the `BROWSER` command and arguments into `exec.Command` directly instead of through `/bin/sh` and checking if that has an automatic escaping mechanism we can take advantage of.
2020-12-20Handle `%s` format string for URL in `BROWSER` variableTeddy Wing
The `BROWSER` environment variable might contain a `%s` format string that should be replaced by the URL to open. If it's present perform the replacement. Otherwise, append the URL to the `BROWSER` command as before.
2020-12-19Add `BROWSER` support to `OpenReader()`Teddy Wing
If the `BROWSER` environment variable is set, open the reader in the given browser. Works by copying the `Reader`'s contents to a temporary file and opening that with `OpenFile()`.
2020-12-19Add `BROWSER` support to `OpenFile()`Teddy Wing
If the `BROWSER` environment variable is set, open the given file path in the given browser.
2020-12-19Add `BROWSER` support to `OpenURL()`Teddy Wing
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.
2020-12-14Wrap `github.com/pkg/browser` in a new `browserenv` packageTeddy Wing
This will be used to extend `browser`'s functionality.