Skip to content

Instantly share code, notes, and snippets.

@Digital-Grinnell
Created January 21, 2023 01:39
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 Digital-Grinnell/49a746444f44abed4ab1d0210d25b52f to your computer and use it in GitHub Desktop.
Save Digital-Grinnell/49a746444f44abed4ab1d0210d25b52f 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