Professional Documents
Culture Documents
home
w3m-reddit
04 Jun 2013
I've been moving a lot of my daily tasks to the command-line lately, and that
includes redditing. I probably spend far too much time on reddit as it is, but I
really wanted to find an efficient way to view reddit through the command-line.
w3m could render reddit okay, but I couldn't view my personal front-page
because that required me to login to my profile.
The solution was cortex, a CLI app for viewing reddit.
However, I kind of got tired of viewing reddit through w3m, the header alone is a
few pages long to scroll through, and the CSS for the comments doesn't load so
there isn't any sense of threading. But, then I discovered reddit's mobile website:
http://reddit.com/.mobile, and it looks absolutely beautiful in w3m. In fact, I think I
prefer it to the normal website in any modern browser; there are no distractions,
just pure content.
In order to get cortex to open the mobile version of reddit, I made a bash script
wrapper around w3m that takes urls and appends ".mobile" to the end of reddit
urls before passing them to w3m (as well as fixing a double forward slash error in
the comment uri cortex outputs that desktop reddit accepts but mobile reddit
404s on). The script:
#!/bin/bash
args=()
until [ -z "$1" ]; do
case "$1" in
Since I regurally use Tmux (with Byobu), I also added an optional -t / --tmux switch
that will open w3m in a temporary new tmux window that will close when w3m is
closed.
I saved the script as w3m-reddit and made it an executable command. In Ubuntu
that's done with the following commands:
$ sudo mv w3m-reddit /usr/bin/
$ sudo chmod +x /usr/bin/w3m-reddit
Now cortex needs to be configured to use w3m-reddit , and that's done by setting
browser-command in the cortex config at ~/.cortex/config to w3m-reddit :
## Command to invoke the webbrowser
## If left empty will try to autodetect the system default browser
##browser-command=firefox '{0}'
browser-command=w3m-reddit '{0}'
There are still some improvements I could make to the w3m-reddit script. Namely,
it should pass along any arguments to itself to w3m underneath. I'm still a newby
at bash though, and I couldn't figure out an easy way to do that without scrapping
the whole thing and starting over in Python instead.
Stay tuned for more posts on how I view images and videos efficiently from the
command-line.
EDIT 04/25/2015: Reddit seems to have gotten rid of their old mobile reddit site
and replaced it with a more modern version that unfortunately doesn't look as
good in w3m. However, the old mobile site is still accessable by adding a ".mobile"
to the end of urls. The script above has been edited to reflect this change.
tyler@hallada.net