Skip to content

Instantly share code, notes, and snippets.

@jmbarbone
Last active February 10, 2021 02:37
Show Gist options
  • Save jmbarbone/d60019c2903ffcaed467ceeafe089009 to your computer and use it in GitHub Desktop.
Save jmbarbone/d60019c2903ffcaed467ceeafe089009 to your computer and use it in GitHub Desktop.
A pre-commit file that will update a datestamp on a file
#!/bin/sh
#
# Update a last commit date tag
#
# Finds the ""@Last commit date:"" tag and updates to current date
# Edited from: https://gist.github.com/johnjohndoe/4024222
d=`date '+%Y-%m-%d'`
# files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
# Retrieves the git diffs and filters out for the file name
files=$(git diff-index --name-status HEAD | grep -v ^D | cut -c3-)
# Check if file is empty or not
if [ "$files" != "" ]
then
for f in $files
do
# This will only be performed on .vba and .vba files
if [[ "$f" =~ [.](vb|vba)$ ]]
then
# This must match exactly
# Will replace in line -- and will replace all text _after_ the tag, too
sed -i "s/@Last commit date:.*$/@Last commit date: $d/g" $f
git add $f
fi
done
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment