amodm/webbrowser-rs

BROWSER environment variable handling doesn't handle multiple browsers or %s escapes

Closed this issue · 2 comments

Thanks for adding the fallback to the $BROWSER environment variable.

However, unlike $PAGER and $EDITOR, $BROWSER doesn't always consist of a single command name that you can run with an URL argument. Quoting man 1 man (one of a few sources fully documenting $BROWSER):

If $BROWSER is set, its value is a colon-delimited list of commands, each of which in turn is used to try to start a web browser for man --html. In each command, %s is replaced by a filename containing the HTML output from groff, %% is replaced by a single percent sign (%), and %c is replaced by a colon (:).

See the documentation for the Python webbrowser module for another explanation of $BROWSER.

So:

  • Split $BROWSER on ':' and loop over each, continuing to the next on failure
  • For each one, replace '%s' with the URL, '%c' with a colon, and '%%' with a percent. If and only if it didn't contain '%s', append the URL.
amodm commented

Sorry about that. I presumed a certain behaviour for $BROWSER. Will fix.

Looks great, thank you!