-
Notifications
You must be signed in to change notification settings - Fork 2
/
gdoc-review
executable file
·53 lines (39 loc) · 1.48 KB
/
gdoc-review
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
#!/usr/bin/bash
GDRIVE_ROOT="/run/user/$(id -u)/gvfs/google-drive:host=redhat.com,user=$(whoami)"
GDRIVE_FOLDER=$(ls $GDRIVE_ROOT | head -1)
# Check if ~/.gdoc-review exists
if [ ! -f ~/.gdoc-review ]; then
echo "~/.gdoc-review attributes file not found. Create it and try again 😥"
exit 1
fi
if [ ! -d "$GDRIVE_ROOT" ]; then
echo "GDrive folder is not mounted. Mount it and try again 😓"
exit 1
fi
if [ $# = 0 ]; then
echo "Provide the AsciiDoc filename as input..."
exit 1
else
FILENAME=$(basename "$1")
FORMATTED_ATTRS=()
# Read the ~/.gdoc-review attributes
while IFS= read -r LINE; do
if [[ -n "$LINE" && ! "$LINE" =~ ^\[ ]]; then
# Split into KEY and VALUE
KEY="${LINE%%=*}"
VALUE="${LINE#*=}"
# Append the attributes to the array
FORMATTED_ATTRS+=("-a" "$KEY=$VALUE")
fi
done < ~/.gdoc-review # Asciidoctor attributes
#Convert the AsciiDoc
asciidoctor --backend docbook -a leveloffset=+1 -a allow-uri-read "${FORMATTED_ATTRS[@]}" -o - "$1" | pandoc --from docbook --to ODT --output "$FILENAME.odt"
gio copy "$FILENAME.odt" $GDRIVE_ROOT/$GDRIVE_FOLDER
echo ""
echo "Sent the review output to Google Drive. Open the output file using Google Docs 👀"
echo "https://drive.google.com/drive/u/0/my-drive?q=type:document%20after:$(date "+%Y-%m-%d")%20parent:$GDRIVE_FOLDER"
xdg-open https://drive.google.com/drive/u/0/search?q=type:document%20parent:$GDRIVE_FOLDER%20creator:me
# Clean up
rm $FILENAME.odt
fi
exit 0