aboutsummaryrefslogtreecommitdiff
path: root/scripts/source-timestamps.sh
blob: 74ff9f05c4310fabbfac18df01f47462c2710114 (plain)
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
#!/bin/sh

# change this with environment
DEFAULT_NOT_SOURCE_REGEX="/\\/assets\\//"
NOT_SOURCE_REGEX="${NOT_SOURCE_REGEX:-$DEFAULT_NOT_SOURCE_REGEX}"
TIMESTAMP_SUFFIX="${SUFFIX:-.timestamp}"
LOGFILE="${LOGFILE:-/dev/null}"

[ -z "$1" ] && echo "$0: no inputs specified?" >/dev/stderr

while [ -n "$1" ]
do
	echo "sourcing directory '$1' ..." >> "$LOGFILE"
	find "$1" -type f -name '*.md' | grep -v "$NOT_SOURCE_REGEX" | while read file ; do
		fn=`basename "$file"`
		dir=`dirname "$file"`
		tsfn="$fn.timestamp"
		(
			echo "making timestamp in '$dir' for file '$fn' ..." >> "$LOGFILE"
			cd "$dir"
			if [ -f "$tsfn" ]
			then echo "... but it already exists; skipping!" >> "$LOGFILE"
			else git log -n 1 --pretty=format:%cs -- "$fn" > "$tsfn"
			fi
		)
	done
	shift
done