-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_book.sh
More file actions
executable file
·27 lines (20 loc) · 857 Bytes
/
commit_book.sh
File metadata and controls
executable file
·27 lines (20 loc) · 857 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
27
#!/usr/bin/env bash
set -euo pipefail
origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit
new_books=$(cd "${origin}/content/book" && git ls-files -o --exclude-standard --full-name)
extract_metadata() {
metadata=$(grep "^${1}:\ *" < "${2}")
metadata="${metadata#"${1}: "}"
echo "${metadata//\"/}"
}
for book in ${new_books}; do
title=$(extract_metadata "title" "${book}")
author=$(extract_metadata "author" "${book}")
isbn=$(extract_metadata "isbn" "${book}")
git add "${book}"
git add "${origin}/content/cover/${isbn}."*
commit_msg="[book][${isbn}] \"${title}\" by \"${author}\""
# use book read date as Git author date (not committer date on purpose)
book_read_date=$(grep "read_date" "${book}" | cut -d' ' -f2 -f3) || book_read_date=$(date "+%Y-%m-%d")
git commit --date="${book_read_date}" -m "${commit_msg}"
done