Some months ago Anders left a note here about a simple script to spill a .epub file into your terminal, without needing another application to read it. Anders credited Esko for the original version, and while it might be presumptuous, I have adjusted Anders’ version slightly too.
Here’s my contribution to the effort, which still needs a little attention at times.
###epub.sh#### if [[ -z "$1" ]] then echo "Usage: ./epub.sh book.epub" exit fi if [[ -z "$2" ]] then COLS=`tput cols` else COLS=$2 fi FILELIST=`zipinfo -1 "$1" | grep -E '\.xml|\.html|\.xhtml' |sort` TEXT="" for FILE in $FILELIST do TEXT="$TEXT `unzip -caa "$1" "$FILE" | html2text -width $COLS`" done echo "$TEXT" | $PAGER ###end####
Which on my screen generates:
My additions to the script are to
- Rely on your $PAGER in the final line,
- Add in support for xhtml files, because the epub I downloaded to test it used xhtml π , and
- Allow you to pick the width of your terminal, or leave it blank to use the full available width.
Of course, like Anders mentioned, this relies on both unzip and html2text, although the latter could be substituted with another tool, if you prefer it.
And it needs a lot of work. The ultimate effect is the “wall of text,” which I personally despise. As you might notice from my short paragraphs on this blog. π
And some better formatting would be nice, as well as some trapping for the leftover HTML that seems to have crept into the display at the top and elsewhere.
But not bad overall. I still count a neverending “Hello World” on my C64 as my greatest programming achievement, but this will do for my contribution. You have my permission to add yours. π
Hello. I’ve just found this. Save it as ~/.html2text.rc
https://raw.githubusercontent.com/vancegroup-mirrors/vrjuggler/master/doc/html2text.rc
It’s the default style of the option “-style pretty” from html2text, but it isn’t packaged on my distro, sadly.
This way, the ebook reading looks more confortable.
And, finally, replacing “html2text -width $COLS” with “elinks”, it just works.
No more html2text encoding errors with some EPUBs π
I never knew elinks was so much poweful.
Oh, and with “elinks -no-references -no-numbering” you get rid of those links which sometimes are inside of a book.
So the script finally is:
###epub.sh####
if [[ -z “$1” ]]
then echo “Usage: ./epub.sh book.epub”
exit
fi
if [[ -z “$2” ]]
then COLS=`tput cols`
else
COLS=$2
fi
FILELIST=`zipinfo -1 “$1″ | grep -E ‘\.xml|\.html|\.xhtml’ |sort`
TEXT=””
for FILE in $FILELIST
do
TEXT=”$TEXT `unzip -caa “$1” “$FILE” | elinks -no-references -no-numbering`”
done
echo “$TEXT” | $PAGER
###end####