Great find! bcat is a small utility to pipe console's output to browser. Do you have a script which outputs HTML? bcat! Do you need to preview a README file with Markdown formatting? bcat! Is your script fetching web pages and you want to see the result? bcat! Do you just simply want to say «hello world» in your browser? You know the answer, right?

Utility is compatible with Linux, Mac OS X and FreeBSD. Theoretically, it should work fine on any Unix-based platform integrated with freedesktop.org.

You can use gem to install bcat:

gem install bcat

Let's test it by opening year of 2014 calendar:

python -c "import calendar ; print calendar.HTMLCalendar().formatyear(2014)" | bcat

A new tab should open in your default browser with the calendar if everything is working properly.

Preview log files

tail -n 1000 -f /var/log/messages | bcat

Now your browser works pretty much like tail.

Here is how the remote log file can be opened:

ssh mywebsite.com 'sudo tail -f /var/log/nginx/access.log' | bcat

Use it as a pager

bcat can be used as a pager for various programs.

man pages:

export MANPAGER='sh -c "col -b | bcat"'

git pages:

export GIT_PAGER=bcat

Now, when you run «man grep» or «git log», the browser's window will be focused and the output will be printed in a new tab. By the way, if you have Git colors enabled, then the colors will also be shown in a browser.

Viewing the clipboard

For Linux:

xclip -o -selection c | bcat

For Mac OS X:

pbpaste | bcat

Markdown

View the Markdown file with formatting:

markdown README.md | bcat

Of course, you can mix different commands. For example, here is how to view the clipboard with Markdown formatting enabled (for Linux):

xclip -o -selection c | markdown | bcat

For Mac OS X:

pbpaste | markdown | bcat

These are just simple examples. I'm sure you can find much more use cases for this handy utility.

Have fun!

[Github]

Subscribe to Kukuruku Hub

Or subscribe with RSS

0 comments