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.
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.😉