January 28, 2013

Newsbeuter RSS reader in the terminal on OSX Mountain Lion

Following my delight in finding and using Mutt for email I started to look for a similar, terminal-based, RSS reader for OSX. I came across Newsbeuter, by Andreas Krennmair, which bills itself as “The Mutt of RSS readers”. And it truly is.

To get started with Newsbeuter you can either download it from the download page or clone it from Github. Either way, you’ll get the compilable source, and that’s where the trouble starts. (Update If you use the Homebrew package manager you can now brew install newsbeuter - Hurrah!)

I couldn’t get OSX Mountain Lion to compile Newsbeuter, it kept throwing error messages like this one:

You need package sqlite3 in order to compile this program.
Please make sure it is installed.

You can download sqlite3 from here:     http://www.sqlite.org/download.html
-n Checking for package libcurl...
not found
-n Checking for package libcurl using curl-config...
found
-n Checking for package libxml-2.0...
not found
-n Checking for package libxml2 using xml2-config...
found
-n Checking for package stfl...
found
-n Checking for package json...
found
-n Checking for package ncurses5.4 using ncurses5.4-config...
found

One or more dependencies couldn't be found. Please install
these packages and retry compilation.
make: *** [config.mk] Error 1

This is despite the fact that I have SQLlite and libxml installed. I tried everything to get Newsbeuter’s makefile to recognise my installed packages, but to no avail.

Then, a little bit of digging found this repo on Github. (I had already tried brew install newsbeuter, no go.) So basically, if you’re using Homebrew as your package manager for OSX you can clone the repo, then

brew tap posativ/homebrew-newsbeuter

and

brew install newsbeuter --HEAD

and you’re done. Newsbeuter is now installed!

The first time that you run newsbeuter you’ll get a message like:

Error: no URLs configured. Please fill the file /home/ak/.newsbeuter/urls with RSS feed URLs or import an OPML file.
newsbeuter 2.4
usage: ./newsbeuter [-i <file>|-e] [-u <urlfile>] [-c <cachefile>] [-x <command> ...] [-h]
-e              export OPML feed to stdout
-r              refresh feeds on start
-i <file>       import OPML file
-u <urlfile>    read RSS feed URLs from <urlfile>
-c <cachefile>  use <cachefile> as cache file
-C <configfile> read configuration from <configfile>
-X              clean up cache thoroughly
-x <command>... execute list of commands
-o              activate offline mode (only applies to Google Reader synchronization mode)
-q              quiet startup
-v              get version information
-l <loglevel>   write a log with a certain loglevel (valid values: 1 to 6)
-d <logfile>    use <logfile> as output log file
-E <file>       export list of read articles to <file>
-I <file>       import list of read articles from <file>
-h              this help

So I added some URLs to ~/.newsbeuter/urls, but still nothing. Luckily, I had exported my exisiting newsfeeds to an OPML file named feeds.opml and running newsbeuter -i feeds.opml imported my feeds into Newsbeuter no problem. (It simply populated ~/.newsbeuter/urls with the feeds from feeds.opml.)

Configuration

Newsbeuter is a joy to configure. Options are written to ~/.newsbeuter/config, and away you go. Here’s a look at my, very basic, config file:

browser open

bookmark-cmd "/Users/larry/pinboard_bookmark.sh"

save-path ~/Documents

color info blue white
color listfocus white yellow

always-display-description true
auto-reload yes
download-full-page yes
mark-as-read-on-hover yes
refresh-on-startup yes

You can get the full list of configuration options from the Newsbeuter manual, which is thorough and well laid out. There’s also an example config file in /newsbeuter/docs

For me, the most interesting settings here are browser open, bookmark-cmd "/Users/larry/pinboard_bookmark.sh" and save-path ~/Documents

Open in Browser

Newsbeuter is configured to use the Lynx browser by default. While I have both Links and W3M installed, I wanted to be able to view certain articles in my regular browser. browser open in ~/.newsbeuter/config allows me to do that. The default key-binding for Open in Browser is o, and now hitting o on any article opens it in my System’s default browser, currently Chrome.

Bookmarking

Newsbeuter allows you to specify scripts as “plugins” to handle bookmarking. (The Github repo contains a number of these in /contrib.) I was pleased to see one, written in Perl, for handling bookmarking to Pinboard, but alas! I could not get it to work.

I dug around in the other supplied scripts and there’s an old one for bookmarking to del.icio.us. Since Pinboard’s api was modelled on the del.icio.us V1 api, I just modified that script to:

#!/bin/sh
# newsbeuter bookmarking plugin for pinboard
# (c) 2007 Andreas Krennmair
# documentation: https://pinboard.in/api

username="pinboard_username"
password="pinboard_password"

tag="via:newsbeuter"

url="$1"
title="$2"
desc="$3"

pinboard_url="https://api.pinboard.in/v1/posts/add?url=${url}&description=${title}&extended=${desc}&tags="${tag}""

output=`wget --http-user=$username --http-passwd=$password -O - "$pinboard_url" 2> /dev/null`

output=`echo $output | sed 's/^.*code="\([^"]*\)".*$/\1/'`

if [ "$output" != "done" ] ; then
  echo "$output"
fi

The bookmark-cmd "/Users/larry/pinboard_bookmark.sh" line in ~./newsbeuter/config specifies the script to use for bookmarking. Now when I hit CTRL-B a bookmark for the current article is sent to my Pinboard account, with the tag via:newsbeuter.

Newsbeuter allows me to edit the link, title and description for the bookmark. These are pre-populated by default, but they show up as blank lines. You can just hit return on each line to save the bookmark, or hit return to save the url, then enter your own title and description when prompted.

Newsbeuter, like Mutt, lets you pipe to commands. To email a link I can use |, which brings up pipe to command, and pipe to mutt -s "Email subject line" recipient@test.com

The only downside to this is I must be able to remember the email address for the recipient, as I can’t use auto-complete for addresses. But I know the addresses of the people I send stuff to, so it’s ok.

Save to File

If you find an article that you’re interested in and want to save locally, hitting s in Newsbeuter saves it as a text file to your local drive. This is really handy for me. The save-path ~/Documents line in ./newsbeuter/config specifies the default save location.