-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunMe.sh
executable file
·71 lines (54 loc) · 1.64 KB
/
RunMe.sh
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
#! /bin/bash
# Usage definition
# Adapted from https://stackoverflow.com/questions/16483119/an-example-of-how-to-use-getopts-in-bash#16496491
usage() { echo "Usage: $0 myfile.ext" 1>&2; exit 1; }
# Check that an argument was passed
if [ -z "$1" ]; then
usage
fi
echo
echo
# Remove temporary files?
flag=0
flag2=0
# Get name and extension separately
pathname=$(dirname "$1")
basename=$(basename "$1")
extension="${basename##*.}"
filename="${basename%.*}"
echo $1
# Make extension all lower case
extensionLowerCase="$(echo "$extension" | tr '[:upper:]' '[:lower:]')"
# Pandoc can't read PDF, so convert to html
if [ "$extensionLowerCase" = "pdf" ]
then
# Run pdf2htmlEX
echo "Converting PDF to HTML..."
docker run -ti --rm -v "${PWD}":/pdf bwits/pdf2htmlex pdf2htmlEX "$1" "$filename".html
basename="$filename".html
flag=1
fi
# Convert file via Pandoc
# "+RTS -K102400000 -RTS" to not get a stack overflow
echo "Converting to WikiText..."
pandoc +RTS -K102400000 -RTS -t wikitext.lua "$1" -o "$filename".tid
# Remove .html file if we converted it from a PDF
if [ "$flag" = 1 ]
then
echo "Removing temporary files..."
# Need -f because pdf2htmlEX write-protects the file
rm -f "$basename"
fi
# Run tiddlyify to clean up the file and add type needed for proper import
echo "Cleaning up WikiText..."
./tiddlify.py "$filename".tid "$1"
# Move .tid file back to original location, if flag
if [ "$flag2" = 1 ]
then
echo "Moving Tiddler back to original location..."
mv "$filename".tid "$pathname"/"$filename".tid
fi
# Move tiddler into tiddler directory in NLFM
mv "$filename".tid ../tiddlers/"$filename".tid
# Done
echo "Done!"