Last active
December 13, 2015 05:56
-
-
Save cubarco/e1b8265a3bc2001790ca to your computer and use it in GitHub Desktop.
Convert txt file to mobi with monospace font using kindlegen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ "$#" -ne 2 ]; then | |
echo "usage: $0 IN_FILE OUT_FILE" | |
exit | |
fi | |
infile=$1; shift | |
outfile=$1 | |
title=${infile%.*} | |
temphtml=$(mktemp /tmp/XXXXXXXXX.html) | |
{ | |
echo '<html>' | |
echo "<title>$title</title>" | |
echo '<body>' | |
echo '<pre>' | |
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' $infile | |
echo '</pre>' | |
echo '</body>' | |
echo '</html>' | |
} > $temphtml | |
tempmobi=$(mktemp /tmp/XXXXXXXXX.mobi) | |
cd /tmp/ | |
# kindlegen does not accept output file contains directory path. | |
kindlegen $temphtml -o $(basename $tempmobi) | |
cd $OLDPWD | |
mv $tempmobi $outfile | |
rm $temphtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment