A more advanced case for opening feed items externally from Newsboat
I am using Newsboat as my RSS reader. I have it running on my home server, which will periodically update the feeds I have subscribed to. And then I have a local script that will SSH into it from whatever computer I'm sitting at. I really like this setup. But I ran into an issue that took some time to solve.
Newsboat is super powerful and can be configured in a ton of different ways. You can read the feed content directly in it. Or you can open the feed item URLs in an external browser. Most of my reading needs are covered by making "open w3m
in a vertical tmux
split, next to Newsboat" as my "open in browser command".
But once in a while, the things I'm reading has important images embedded in them or other visual elements that a browser in a terminal does not render well. In these cases I prefer opening the URLs in the Firefox running on the machine I'm physically sitting at, from which I SSH'ed into the server running Newsboat.
Sure, this can be done by clicking or copy/pasting the URL from Newsboat in the terminal. But one of the points of using Newsboat is to keep my hands on they keyboard as much as possible and leave the mouse alone. I solved this with the macros in Newsboat.
With a macro, you can string together several commands, thus achieving more complex tasks than just "open" or "mark read". So I created the following macro:
macro f set browser "ssh localhost -p2221 DISPLAY=:0 firefox %u"; open-in-browser ; set browser "tmux split-window -hb -l 80 w3m %u"
What it does is:
- Change the
browser
command from thew3m
in atmux
split to instead SSH from the remote server back to my local machine and open the URL in Firefox there. - Use the
open-in-browser
command which will then open the given URL. - Change the
browser
command back to what it was before.
This, of course, requires a reverse port forward in the SSH connection, but I have build this into the Newsboat script I'm running locally to open the SSH connection, so I never have think about this. it also does other things, which I will cover later.
Thus, by typing ,f
in Newsboat, I can open the current feed item in my local Firefox, without taking my hands off the keyboard. Neat!
But this stopped working a while back. And I never got around to trying to fix it until now. I was getting this error:
Authorization required, but no authorization protocol specified
Error: cannot open display: :0
After a bit of searching the internet, it turned out that I need to specify an XAUTHORITY
environment variable along with the one for DISPLAY
. This should point to an authority file, which used to be located at $HOME/.Xauthority
. But (it seems) after Ubuntu switched from X to Wayland, this is no longer the case.
Instead I found out mine is located at /run/user/1000/.mutter-Xwaylandauth.RPLA81
. The "RPLA81"
suffix indicates that this occasionally changes (after a reboot or what do I know) and probably also varies across computers. So I didn't want to just copy paste this value in. Instead, I expanded the SSH command to include another SSH call to the remote server, in order to determine the location of this file:
ssh localhost -p2221 XAUTHORITY=`ssh localhost -p2221 ls /run/user/1000/.mutter-*` DISPLAY=:0 firefox %u
And now my Newsboat macro works again, yay!
For the full picture, my local script for starting Newsboat remotely via SSH looks like this:
ssh remote-server -R 2221:localhost:2222 -t \
"tmux -2 new-session -d -s newsboat; tmux -2 a -t newsboat \; new-window \
'newsboat || (echo \"Unable to start newsboat. The reload cron job is \
probably running. Try again in a few seconds.\" && read -s OKAY)' \; \
swap-window -s 1 -t 2 \; kill-window -t 2"
Apart from setting up the reverse port forwarding, it also makes sure to run Newsboat in a tmux
session called "newsboat"
, preparing the whole things for the tmux
splits I previously talked about.
I consider this a prime example of using software following the Unix philosophy ideas write programs that do one thing and do it well and write programs to work together: By mixing ssh
, tmux
, w3m
and even firefox
together in the right way, I have a super useful setup for reading whatever my feeds bring me.