Dominic Reich
cde1a604b4
it automaticalle replaces lastmod with an actual date and time but removes the possibility to select hunks (did not work properly anyway) JUST DONT SELECT HUNKS FOR COMMITS AS THE WHOLE FILE WILL BE COMMITED AGAIN!
14 lines
688 B
Bash
Executable file
14 lines
688 B
Bash
Executable file
#!/bin/sh
|
|
# Contents of .git/hooks/pre-commit
|
|
# Replace `last_modified_at` timestamp with current time
|
|
# https://mademistakes.com/notes/adding-last-modified-timestamps-with-git/
|
|
# enhanced the script to either update the YAML or TOML frontmatter (as i used both O_o)
|
|
|
|
git diff --cached --name-status | grep -E -i "^(A|M).*\.(md)$" | while read a b; do
|
|
# YAML or TOML frontmatter?
|
|
(grep -E "^---$" $b > /dev/null) && (cat $b | sed "/---.*/,/---.*/s/^lastmod:.*$/lastmod: $(date -u "+%Y-%m-%dT%H:%M:%S%z")/" > tmp)
|
|
(grep -E "^\+\+\+$" $b > /dev/null) && (cat $b | sed "/+++.*/,/+++.*/s/^lastmod.*$/lastmod = '$(date -u "+%Y-%m-%dT%H:%M:%S%z")'/" > tmp)
|
|
mv tmp $b
|
|
git add $b
|
|
done
|
|
|