# Packages
No description provided by the author
# README
Introduction
browser is a dependency-free library for opening URLs (or files) in the most appropriate browser or assigned application, respectively. Based on the operating system and available executables, it tries to open URLs in the following sequence:
- command defined by the environment variable
$BROWSER
(if set) - operating system specific launcher
- macOS:
/usr/bin/open
- Windows:
cmd /c start
- otherwise:
xdg-open
(if environment variable$DISPLAY
is set)
- macOS:
- one of the following binaries from
$PATH
chrome
google-chrome
chromium
firefox
Use browser as library
Installation
go get -d -u github.com/abc-inc/browser
Usage
import "github.com/abc-inc/browser"
...
if ok := browser.Open(url); !ok {
// something bad happened
}
Use browser as standalone application
Installation
go get -u github.com/abc-inc/browser
Examples
# open a URL in the default browser
browser http://localhost/
# open a local file in the default browser
browser file:///C:/Temp/report.html
# macOS: use Firefox even if another default web browser is set
BROWSER="open -a Firefox" browser http://localhost/file.zip
# download a file with wget or curl - whatever is available
BROWSER="wget:curl -o index.html" browser http://localhost/
Since browser leverages operating system specific launchers, it can also be used to open other files and directories:
# play audio file using the media player associated with the file type
browser file:///home/me/Music/track.mp3
# open a folder in Visual Studio Code or vi (must be installed separately)
BROWSER=code:vi browser file:///Users/me/dev/project
Similar Projects
- github.com/pkg/browser: the de facto standard implementation
- github.com/hashicorp/terraform/command/webbrowser: encapsulates pkg/browser and provides a mock implementation for testing purposes.
Feature | abc-inc/browser | pkg/browser | hashicorp/terraform |
---|---|---|---|
Windows/Linux/macOS/OpenBSD | :ballot_box_with_check: | :ballot_box_with_check: | :ballot_box_with_check: |
FreeBSD/NetBSD (xdg-open) | :ballot_box_with_check: | ||
WSL support | :ballot_box_with_check: | ||
$BROWSER support | :ballot_box_with_check: | ||
open from io.Reader | :ballot_box_with_check: | ||
mock support | :ballot_box_with_check: | ||
custom Cmd (Args, Dir, Env, etc.) | :ballot_box_with_check: |