Skip to content

Instantly share code, notes, and snippets.

@SummittDweller
Last active January 21, 2023 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SummittDweller/b0f685fc07d01aaf33fb4a5bec37cfac to your computer and use it in GitHub Desktop.
Save SummittDweller/b0f685fc07d01aaf33fb4a5bec37cfac to your computer and use it in GitHub Desktop.
My 'pre-commit' git Hook
# 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