2014-07-24 03:21:28 +00:00
|
|
|
---
|
|
|
|
title: w3m-reddit
|
|
|
|
layout: post
|
2014-07-30 03:33:16 +00:00
|
|
|
redirect_from: "/blog/w3m-reddit/"
|
2014-07-24 03:21:28 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
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](http://reddit.com) as it is, but I really wanted to find an efficient
|
|
|
|
way to view reddit through the command-line. [w3m](http://w3m.sourceforge.net/)
|
|
|
|
could render reddit okay, but I couldn't view my personal front-page because
|
|
|
|
that required me to login to my profile.
|
2018-04-27 03:50:52 +00:00
|
|
|
<!--excerpt-->
|
2014-07-24 03:21:28 +00:00
|
|
|
|
|
|
|
The solution was [cortex](http://cortex.glacicle.org/), 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
|
2015-04-24 20:24:54 +00:00
|
|
|
website: [http://reddit.com/.mobile](http://reddit.com/.mobile), and it looks absolutely
|
2014-07-24 03:21:28 +00:00
|
|
|
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.
|
|
|
|
|
2014-07-28 19:13:49 +00:00
|
|
|
<a href="/img/blog/w3m_mobile_reddit.png"><img src="/img/blog/w3m_mobile_reddit.png" alt="m.reddit.com rendered in w3m"></a>
|
2014-07-24 03:21:28 +00:00
|
|
|
|
|
|
|
In order to get cortex to open the mobile version of reddit, I made a bash
|
2015-04-24 20:24:54 +00:00
|
|
|
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:
|
2014-07-24 03:21:28 +00:00
|
|
|
|
2016-02-03 17:53:10 +00:00
|
|
|
~~~ bash
|
2014-07-24 17:00:30 +00:00
|
|
|
#!/bin/bash
|
2014-07-24 03:21:28 +00:00
|
|
|
|
2014-07-24 17:00:30 +00:00
|
|
|
args=()
|
|
|
|
until [ -z "$1" ]; do
|
|
|
|
case "$1" in
|
|
|
|
-t|--tmux) t=1; shift ;;
|
|
|
|
--) shift ; break ;;
|
|
|
|
-*) echo "invalid option $1" 1>&2 ; shift ;; # or, error and exit 1 just like getopt does
|
|
|
|
*) args+=("$1") ; shift ;;
|
|
|
|
esac
|
|
|
|
done
|
2014-07-24 03:21:28 +00:00
|
|
|
|
2014-07-24 17:00:30 +00:00
|
|
|
args+=("$@")
|
|
|
|
for arg in "${args[@]}" ; do
|
|
|
|
# Switch to mobile reddit
|
2015-04-24 20:11:50 +00:00
|
|
|
url=$arg
|
|
|
|
mobile='.mobile'
|
|
|
|
if [[ $url =~ http:\/\/www.reddit.com || $url =~ http:\/\/reddit.com ]]
|
|
|
|
then
|
|
|
|
if [[ $url =~ \/$ ]]
|
|
|
|
then
|
|
|
|
url=$url$mobile
|
|
|
|
else
|
|
|
|
url=$url'/'$mobile
|
|
|
|
fi
|
|
|
|
fi
|
2014-07-24 17:00:30 +00:00
|
|
|
# Fix double backslash error in comment uri for mobile reddit
|
|
|
|
url=${url/\/\/comments/\/comments}
|
|
|
|
if [[ $t == "1" ]]; then
|
|
|
|
tmux new-window 'w3m "'${url}'"'
|
|
|
|
else
|
|
|
|
w3m "${url}"
|
|
|
|
fi
|
|
|
|
done
|
2016-02-03 17:53:10 +00:00
|
|
|
~~~
|
2014-07-24 03:21:28 +00:00
|
|
|
|
|
|
|
Since I regurally use [Tmux](http://tmux.sourceforge.net/) (with
|
|
|
|
[Byobu](http://byobu.co/)), 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:
|
|
|
|
|
2016-02-03 17:53:10 +00:00
|
|
|
~~~ bash
|
2014-07-24 17:00:30 +00:00
|
|
|
$ sudo mv w3m-reddit /usr/bin/
|
|
|
|
$ sudo chmod +x /usr/bin/w3m-reddit
|
2016-02-03 17:53:10 +00:00
|
|
|
~~~
|
2014-07-24 03:21:28 +00:00
|
|
|
|
|
|
|
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}'
|
|
|
|
|
|
|
|
The result is a distraction-free reddit experience right in the command-line
|
|
|
|
without having to edit cortex directly. I've found that I even prefer reddit
|
|
|
|
this way. Without image thumbnails (I need to explicitly select the image links
|
|
|
|
to view the image in w3m) I am more inclined to pay equal attention to every
|
|
|
|
post, not just mindlessly scrolling through meme-fests. Thus I'm more focused
|
|
|
|
and tend to not loose myself like I do in the infinite scrolling of [RES
|
|
|
|
reddit](http://redditenhancementsuite.com/) in a GUI browser.
|
|
|
|
|
|
|
|
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.
|
2015-04-24 19:03:18 +00:00
|
|
|
|
|
|
|
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
|
2015-04-24 20:11:50 +00:00
|
|
|
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.
|