-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-note-header.sh
More file actions
executable file
·26 lines (25 loc) · 903 Bytes
/
add-note-header.sh
File metadata and controls
executable file
·26 lines (25 loc) · 903 Bytes
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
#!/usr/bin/env bash
set -e
NOTES_PATH=${1:-testbed}
find $NOTES_PATH -type f -name "*.md" -print0 | while IFS= read -r -d '' file; do
echo "Adding tags to $file ..."
filename=$(basename -- "$file")
title="${filename%.*}"
notebook="$(basename "$(dirname "$(realpath "$file")")")"
mtime=$(date -r "$file" --iso-8601=seconds)
ctime=$mtime
TAGS="tags: [Notebooks/$notebook]"
TITLE="title: $title"
CREATED="created: '$ctime'"
MODIFIED="modified: '$mtime'"
touch -r "$file" timestamp
echo -e "---\n" | cat - "$file" > temp && mv temp "$file"
echo $MODIFIED | cat - "$file" > temp && mv temp "$file"
echo $CREATED | cat - "$file" > temp && mv temp "$file"
echo $TITLE | cat - "$file" > temp && mv temp "$file"
echo $TAGS | cat - "$file" > temp && mv temp "$file"
echo "---" | cat - "$file" > temp && mv temp "$file"
touch -r timestamp "$file"
echo done.
done
rm timestamp