-
Notifications
You must be signed in to change notification settings - Fork 1
/
note-new
executable file
·45 lines (32 loc) · 1.08 KB
/
note-new
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
#!/bin/bash
required_date="${1:-today}"
initialLocation="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${initialLocation}/scripts/gnudate.sh
rootFolder="$( cat "${initialLocation}/.noteFolderPath")"
if [ -z $rootFolder ]; then
echo "Can't find root folder '${rootFolder}', did you run note-setup?"
exit 1
fi
formated_date="$( gnudate -d "${required_date}" +'%Y-%m-%d' )"
noteFolderLocation="${rootFolder}/journal"
filePath="${noteFolderLocation}/${formated_date}.md"
if [ ! -d "${noteFolderLocation}" ]
then
mkdir -p "${noteFolderLocation}"
fi
if [ ! -e $filePath ]
then
# Create today's file based on template
cp "${rootFolder}/.template.md" "${filePath}"
echo "Applying sections to ${filePath}:"
sections=$(cat "${rootFolder}/.sections")
if [[ ! -z $sections ]]; then
for section in $sections; do
echo "* ${section}"
cat "${rootFolder}/.section.${section}".md >> "${filePath}"
rm "${rootFolder}/.section.${section}".md
done
fi
fi
echo "Editing file ${filePath}"
$EDITOR "${filePath}"