Skip to content
Snippets Groups Projects
Commit 81f1e0e4 authored by Kaan Cimir's avatar Kaan Cimir
Browse files

add timestamp sourcing script

parent 85fed0b7
No related branches found
No related tags found
No related merge requests found
#!/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
TIMESTAMP=`git log -n 1 --pretty=format:%cs -- "$fn"`
mv "$fn" "$fn.temporary"
head -n1 "$fn.temporary" > "$fn"
echo "timestamp: \"$TIMESTAMP\"" >> "$fn"
tail -n+2 "$fn.temporary" >> "$fn"
rm -f "$fn.temporary"
fi
)
done
shift
done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment