Skip to content

Commit

Permalink
Fix last modified script to only change staged files
Browse files Browse the repository at this point in the history
  • Loading branch information
bchiang7 authored and Alec Marcus committed Feb 5, 2021
1 parent 4b88467 commit 8c2703e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scripts/last_modified.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
git diff --name-only HEAD | while read filename; do
if [[ "${filename##*.}" == "md" ]]; then
# Get staged files
git diff --name-only --cached HEAD | while read filename; do
# If the file exists and ends in `.md` then update the date field
if [[ -f "$filename" && "${filename##*.}" == "md" ]]; then
last_modified=`date +"%Y-%m-%d"`
sed -i "" "s|date:.*|date: $last_modified|g" "$filename"
echo "Updating timestamp for $filename"
git add $filename
fi
done

git add .

# This sets all .md files to have the same last edit dates as the Git log.
# It shouldn't actually need to be run, but keeping it here for posterity.
# git ls-tree -r --name-only HEAD | while read filename; do
Expand Down

0 comments on commit 8c2703e

Please sign in to comment.