Skip to content

romiras/bv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bv (Browser View)

bv is a command-line utility that pipes standard input and displays it in a web browser. It starts a local web server on a random port and opens a new browser window/tab to view the content.

This is useful for quickly viewing logs, command output, or any text-based data in a browser.

Features

  • Streams standard input to a connected browser client.
  • Automatically opens your default web browser to the correct address.
  • Basic content-type sniffing: detects if the input is HTML and sets the Content-Type header accordingly.
  • Option to manually set the Content-Type via the -ct flag.
  • Wraps plain text in <pre> tags for proper formatting.
  • Graceful shutdown of the server after the input stream closes.

Installation and Usage

Building

To build the bv binary, run the following command:

go build

This will create an executable file named bv in the current directory.

Running

You can pipe any command's standard output to bv.

Examples:

View a directory listing:

ls -l | ./bv

View a source file:

cat main.go | ./bv

View an HTML file (bv will detect the HTML and render it):

cat tests/sample.html | ./bv

Specify a different content type (e.g., for an SVG image):

cat tests/sample.svg | ./bv -ct image/svg+xml

Command-line Options

  • -ct: Sets the Content-Type of the HTTP response. Defaults to text/plain. If the input starts with <, it's automatically changed to text/html unless -ct is specified.

Inspiration

Original idea & implementation by Ryan Tomayko in bcat.

Credits

The graceful shutdown implementation was inspired by several online resources:

About

Browser View - use web-browser for piping stdout like "less"

Topics

Resources

Stars

Watchers

Forks