refined created date based on git blame
This commit is contained in:
parent
d546b02cc4
commit
e225747abd
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cwd=`dirname "${0}"`
|
cwd=`dirname "${0}"`
|
||||||
|
|
||||||
function rewritedate () {
|
function rewritedate () {
|
||||||
echo "$1 : $2"
|
echo "$1 : $2"
|
||||||
echo $2 | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$1"
|
echo $2 | xargs -I{} yq -i --front-matter="process" '.date="{}"' "$1"
|
||||||
@ -9,16 +10,26 @@ IFS=$'\n'
|
|||||||
for f in $FILES
|
for f in $FILES
|
||||||
do
|
do
|
||||||
BDATE=$(stat -f "%SB" "$f");
|
BDATE=$(stat -f "%SB" "$f");
|
||||||
DATE=$(LC_ALL=C date -j -Iseconds -f "%b %d %H:%M:%S %Y" "$BDATE");
|
DATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" "+%FT%T%z");
|
||||||
FLINE=$(head -n 1 "$f");
|
FLINE=$(head -n 1 "$f");
|
||||||
ORIGINDATE=$(yq --front-matter=extract '.date' "$f" | date "+%s")
|
|
||||||
LOCALDATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" | date "+%s");
|
LOCALDATE=$(LC_ALL=C date -j -f "%b %d %H:%M:%S %Y" "$BDATE" "+%s" );
|
||||||
GITDATE=$(git blame $f | grep -Eo '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}'| xargs -I{} date -j -f "%Y-%m-%d %H:%M:%S" "{}" | date "+%s");
|
GITDATERAW=$(git blame $f |tail -1| grep -Eo '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}');
|
||||||
|
GITDATE=$(LC_ALL=C date -j -f "%Y-%m-%d %H:%M:%S" "$GITDATERAW" "+%s");
|
||||||
|
GITDATE_2=$(LC_ALL=C date -j -f "%Y-%m-%d %H:%M:%S" "$GITDATERAW" "+%FT%T%z");
|
||||||
if [[ "$FLINE" == "---" ]];
|
if [[ "$FLINE" == "---" ]];
|
||||||
then
|
then
|
||||||
|
ORIGINDATE_RAW=$(yq --front-matter=extract '.date' "$f")
|
||||||
|
ORIGINDATE=$(date -j -f "%FT%T%z" "$ORIGINDATE_RAW" "+%s")
|
||||||
|
|
||||||
if [ $LOCALDATE -lt $ORIGINDATE ]; then
|
if [ $LOCALDATE -lt $ORIGINDATE ]; then
|
||||||
echo "$f has frontmatter and date of local file is older. overwriting."
|
echo "$f has frontmatter and date of local file is older. overwriting."
|
||||||
rewritedate $f $BDATE
|
rewritedate $f $DATE
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $GITDATE -lt $LOCALDATE ]; then
|
||||||
|
echo "Oldest commit date is older than birth date. overwriting"
|
||||||
|
rewritedate $f $GITDATE_2
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "$f has no frontmatter, adding to it";
|
echo "$f has no frontmatter, adding to it";
|
||||||
|
Loading…
Reference in New Issue
Block a user