-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
convert-evernote-to-markdown.sh
executable file
·80 lines (67 loc) · 1.62 KB
/
convert-evernote-to-markdown.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
72
73
74
75
76
77
78
#!/bin/bash
#
# Imports a notebook from Evernote into Markdown files
#
# Errors are fatal
set -e
if test ! "$1"
then
echo "! "
echo "! Syntax: $0 directory"
echo "! "
echo "! directory - The directory containing Evernote .enex format notebooks"
echo "! "
exit 1
fi
NOTEBOOK=$1
TARGET="markdown-exports"
if test ! $(which yarle)
then
echo "# Installing yarle..."
npm install -g yarle-evernote-to-md
else
echo "# Yarle already installed..."
fi
#
# Write our configuration file which Yarle uses.
#
cat config.json.in \
| sed -e "s|%DIR%|$(pwd)|g" -e "s|%NOTEBOOK%|${NOTEBOOK}|g" -e "s|%TARGET%|${TARGET}|g" \
> config.json
yarle --configFile ./config.json
#
# This crazy logic here is to do the following:
#
# 1) Move the various notebooks out of the notes/ directory and into the parent, because
# I see not point to the notes/ directory existing.
#
# 2) In an effort to make things more user-friendly, if this script has been run before,
# simply add an ascending number to the end and try again, instead of having the script bail.
#
#
echo
echo
echo "# Moving directories from ${TARGET}/notes/ into just ${TARGET}..."
pushd ${TARGET} > /dev/null
for FILE in notes/*
do
DEST=$(basename "${FILE}")
if test -e "${DEST}"
then
I=1
DEST="${DEST}.${I}"
echo "# Checking for ${DEST}..."
while test -e "${DEST}"
do
echo "# Looks like ${DEST} already exists, let's increment and try again..."
I=$(( I += 1 ))
DEST=$(basename "${FILE}")
DEST="${DEST}.${I}"
done
echo "# Our new target will be ${DEST}!"
fi
echo "# Moving notes/${FILE} to ${DEST}..."
mv "${FILE}" "${DEST}"
done
rm -rf notes
popd > /dev/null