-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·107 lines (82 loc) · 1.88 KB
/
run
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
PDF_FILENAME=slides.pdf
RST_FILENAME="${RST_FILENAME:-slides.rst}"
THUMBNAIL_FILENAME=thumbnail.jpg
function clean {
rm -fr dist/*
touch dist/.keep
find . \
-type f \( -name "${PDF_FILENAME}*" -o -name *.build_temp -o -name ${THUMBNAIL_FILENAME} \) \
-delete
}
function generate {
generate:pdf "${@}"
}
function generate:pdf {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
DIRECTORY_NAME=$1
shift 1
pushd "src/${DIRECTORY_NAME}"
rst2pdf "${RST_FILENAME}" \
--break-level 1 \
-e preprocess \
--fit-background-mode scale \
--font-path ../fonts \
--output "../../dist/${DIRECTORY_NAME}.pdf" \
--stylesheets ../styles/opdavies-light,tango \
"${@}"
popd
tree dist
}
# Generate JPG thumbnails of each slide in a presentation.
function generate:thumbnail {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [ ! -d "src/${1}" ]; then
echo "${1} not found"
exit 2
fi
generate:pdf "${1}"
mkdir -p "dist/${1}"
gs \
-dBATCH \
-dDownScaleFactor=3 \
-dNOPAUSE \
-r600 \
-sDEVICE=jpeg \
-sOutputFile="dist/${1}/%d.jpg" \
"dist/${1}.pdf"
}
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# Create a new talk.
function new {
if [ "${1}" == "" ]; then
echo "Usage: ./${0##*/} ${FUNCNAME[0]} <talk-name>"
exit 1
fi
if [[ -e "src/${1}" ]]; then
echo "Error: ${1} already exists."
exit 1
fi
mkdir -vp "src/${1}"
touch "src/${1}/slides.rst"
}
function present {
TALK_PATH=$1
shift 1
pdfpc "${@}" "dist/${TALK_PATH}.pdf"
}
TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"