browserenv

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2020 License: MPL-2.0 Imports: 9 Imported by: 0

README

browserenv

GoDoc

Browserenv allows URLs and files to be opened in a local web browser. It is a drop-in replacement for the github.com/pkg/browser package.

If the BROWSER environment variable is set, the input URL will be opened using the command it defines rather than the system's default web browser. When BROWSER is not defined, github.com/pkg/browser is used.

Examples

Set BROWSER to a command that opens a URL. The URL is appended as an argument to the command:

BROWSER="open -a Firefox"

If %s is included in the command, it is replaced with the URL:

BROWSER="open -a Firefox '%s'"

Multiple commands can be specified, delimited by colons. The commands will be tried from left to right, stopping when a command exits with a 0 exit code.

BROWSER="w3m '%s':open -a Firefox"

A sample program:

package main

import (
	"strings"

	"github.com/teddywing/browserenv"
)

func main() {
	browserenv.OpenFile("file.gif")

	browserenv.OpenReader(strings.NewReader("Reader content"))

	browserenv.OpenURL("https://duckduckgo.com")
}

License

Copyright © 2020 Teddy Wing. Licensed under the Mozilla Public License v. 2.0 (see the included LICENSE file).

Documentation

Overview

Package browserenv allows URLs and files to be opened in a local web browser. The system's default browser is used. If the BROWSER environment variable is set, the command it specifies is used instead.

If the BROWSER variable contains the string "%s", that will be replaced with the URL. Otherwise, the URL is appended to the contents of BROWSER as its final argument.

BROWSER can contain multiple commands delimited by colons. Each command is tried from left to right, stopping when a command exits with a 0 exit code.

Index

Constants

This section is empty.

Variables

View Source
var Stderr io.Writer = os.Stderr

Stderr is the browser command's standard error Writer. Defaults to os.Stderr.

View Source
var Stdout io.Writer = os.Stdout

Stdout is the browser command's standard output Writer. Defaults to os.Stdout.

Functions

func OpenFile

func OpenFile(path string) error

OpenFile opens the file referenced by path in a browser.

func OpenReader

func OpenReader(r io.Reader) error

OpenReader copies the contents of r to a temporary file and opens the resulting file in a browser.

func OpenURL

func OpenURL(url string) error

OpenURL opens url in a browser.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL