Last active
January 21, 2023 01:33
-
-
Save SummittDweller/b0f685fc07d01aaf33fb4a5bec37cfac to your computer and use it in GitHub Desktop.
My 'pre-commit' git Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Contents of ~/gitconfig/hooks/pre-commit | |
# Replace `last_modified_at` timestamp with current time in the specified TZ for .md edits only | |
# Note that this file should exist on your workstation as `~/gitconfig/hooks/pre-commit` and the file must be executable! | |
git diff --cached --name-status | egrep -i "^(A|M).*\.(md)$" | while read a b; do | |
cat $b | sed "/---.*/,/---.*/s/^last_modified_at:.*$/last_modified_at: $(TZ=CST6CDT date "+%Y-%m-%dT%H:%M:%S")/" > tmp | |
mv tmp $b | |
git add $b | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment