-
Notifications
You must be signed in to change notification settings - Fork 0
/
cafe
67 lines (56 loc) · 1.76 KB
/
cafe
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# cafe (Convert All File Extensions)
# Get the file name and format
file=$1
filename=$(basename -- "$file")
extension="${filename##*.}"
filename="${filename%.*}"
check_completion=0
# Supported formats for conversion
pandoc_formats="markdown html latex odt epub docx"
calibre_formats="pdf mobi azw3"
# usage function for the script
usage() {
echo "Usage: file-converter [file]"
echo "Converts a file to all supported formats using pandoc and Calibre."
echo ""
echo "Options:"
echo " file The input file to be converted."
echo ""
echo "The script assumes that pandoc and Calibre are installed and available in the PATH."
echo "If they are installed in a different location, you need to specify the correct path to the executable."
exit 1
}
while getopts 'f:h' flag; do
case "${flag}" in
f) file="${OPTARG}" ;;
h) usage
exit 0
;;
*) usage
exit 1
;;
esac
done
# Check if pandoc and Calibre are installed
if ! command -v pandoc &> /dev/null; then
echo "Error: pandoc is not installed. Please install pandoc and try again."
exit 1
fi
if ! command -v ebook-convert &> /dev/null; then
echo "Error: Calibre is not installed. Please install Calibre and try again."
exit 1
fi
# Convert file to all supported formats using pandoc
for format in $pandoc_formats; do
pandoc "$file" -s -o "$filename.$format" && check_completion=$((check_completion+1))
done
# Convert file to all supported formats using Calibre
for format in $calibre_formats; do
ebook-convert "$file" "$filename.$format" && check_completion=$((check_completion+1))
done
if [[ $check_completion -eq 2 ]] then
echo "Conversion completed successfully."
else
echo "Conversion incompleted failed to complete conversion."
fi