bcat: view console output in a browser

  • Tutorial
I was surprised to find that no one on Habrahabr wrote about bcat . This is a small convenient utility for viewing console output in a browser. Do you have a script that returns HTML? Bcat! Need a simple preview for the Markdown formatted README file you just added? Bcat! Write a website parser and want to see what kind of error the site returns? Bcat! There is a big log, and you want it to appear in black and white, and be convenient to read? Well, you get it, right? :)

The program runs on Linux, Mac OS X and FreeBSD (and, theoretically, on any UNIX-like platform with freedesktop.org integration).

You can use gem to install bcat:

gem install bcat

Rack is installed with bcat (unless, of course, it has already been installed before).

To check, you can try to open the calendar for 2014:

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

If a new tab opens in the browser and a calendar appears in it, then everything works correctly.

View Logs

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

The text in the browser will be updated as new lines appear in the log.

The log on the remote server can be viewed as follows:

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

Use as a pager

You can use bcat as a pager for different programs.

For man:

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

For git:

export GIT_PAGER=bcat

After that, when you start, for example, “man grep” or “git log”, the focus switches to the browser window, and the command output opens in a new tab. By the way, if color output is enabled in Git, then the colors will be displayed in the browser too.

View clipboard

For Linux:

xclip -o -selection c | bcat

For Mac OS X:

pbpaste | bcat

Markdown

View a Markdown file with formatting:

markdown README.md | bcat

Teams, of course, can be docked as you like. For example, you can view the contents of the clipboard with Markdown formatting like this (for Linux):

xclip -o -selection c | markdown | bcat

Or so (for Mac OS X)

pbpaste | markdown | bcat

Testing the Django template

Let's say that in the current working directory there is a template template.html, and you want to see how it will be displayed with a specific context.

Create the preview_template.py file and run the following command:

python preview_template.py template.html "{'username': 'Његош'}"

The browser immediately opens the result of rendering the template.

Of course, these are just examples, but in general, you can use bcat for a huge variety of everyday tasks.

See also




Also popular now: