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.
- 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-Typeheader accordingly. - Option to manually set the
Content-Typevia the-ctflag. - Wraps plain text in
<pre>tags for proper formatting. - Graceful shutdown of the server after the input stream closes.
To build the bv binary, run the following command:
go buildThis will create an executable file named bv in the current directory.
You can pipe any command's standard output to bv.
Examples:
View a directory listing:
ls -l | ./bvView a source file:
cat main.go | ./bvView an HTML file (bv will detect the HTML and render it):
cat tests/sample.html | ./bvSpecify a different content type (e.g., for an SVG image):
cat tests/sample.svg | ./bv -ct image/svg+xml-ct: Sets theContent-Typeof the HTTP response. Defaults totext/plain. If the input starts with<, it's automatically changed totext/htmlunless-ctis specified.
Original idea & implementation by Ryan Tomayko in bcat.
The graceful shutdown implementation was inspired by several online resources: