-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkindle
55 lines (50 loc) · 1.55 KB
/
kindle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
# Function to sync books from local directory with your Kindle.
# Be sure to fill in the following variables (first three lines of function):
# TO
# FROM
# TYPE
# The ${TYPE} varible is the file extension for the books: pdf, mobi, epub, etc.
#
# PDFs can be converted to the Kindle format so you can take advantage of functionality
# such as variable font size, annotations, and Whispersync. To have a document converted
# to Kindle format (.azw), set the ${CONVERT} variable to 'yes'.
#
# You can read more about this process at:
# https://www.amazon.com/gp/sendtokindle/email
function books {
local TO=
local FROM=
local TYPE=
local -l CONVERT=no
local -l ANS
local -i COUNT=$((ls *.${TYPE} | wc -l) 2> /dev/null)
# Font color.
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
NF=$(tput sgr0) #No Formatting.
if [ "${TYPE,,}" == "pdf" ] && [ "${CONVERT}" == "yes" ]; then
local SUBJECT=convert
else
local SUBJECT=" "
fi
if [ ${COUNT} -gt 0 ]; then
echo -e " Greetings Reader. I have found the following ${RED}${COUNT}${NF} book(s):\n"
ls *.${TYPE}
echo -e "\nWould you like to send these book(s) to your Kindle?"
read -p "N/y > " ANS
else
echo "No '${RED}${TYPE}${NF}' books found in the current directory: ${PWD}"
return 1
fi
if echo ${ANS} | grep '^y' > /dev/null 2>&1; then
for book in *.${TYPE}; do
echo | mail -a ${book} -s ${SUBJECT} -r ${FROM} ${TO}
done
fi
}