I was surprised to find that no one on Habrahabr wrote about
bcat . This is a small handy utility for viewing the output of console programs in the browser. Do you have a script that returns HTML? Bcat! Need a simple preview for the Markdown format README file that you just added? Bcat! Write the website parser, and want to see what the site returns for an error? Bcat! There is a large log, and you want it to be displayed in black and white, and it was easy to read? Well, you understand, yes? :)
The program works on Linux, Mac OS X and FreeBSD (and, theoretically, on any UNIX-like platform with the integration of freedesktop.org).
To install bcat, you can use gem:
')
gem install bcat
Together with bcat, a rack is installed (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 has opened in the browser, and the calendar is displayed in it, then everything is working 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.
Log on the remote server can be viewed as:
ssh mywebsite.com 'sudo tail -f /var/log/nginx/access.log' | bcat
Use as a pagerYou 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 launch, 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, the colors will be displayed in the browser too.
View ClipboardFor Linux:
xclip -o -selection c | bcat
For Mac OS X:
pbpaste | bcat
MarkdownView Markdown file with formatting:
markdown README.md | bcat
Teams, of course, can be docked whatever you like. For example, you can view the contents of the clipboard with Markdown formatting (for Linux):
xclip -o -selection c | markdown | bcat
Or so (for Mac OS X)
pbpaste | markdown | bcat
Testing a Django TemplateSuppose there is a template.html in the current working directory and you want to see how it will be displayed with a specific context.
Create a file
preview_template.py and run the following command:
python preview_template.py template.html "{'username': 'Њ'}"
The result of template rendering is immediately opened in the browser.
Of course, these are just examples, and in general bcat can be used for a huge variety of everyday tasks.
See also