Created
January 30, 2023 20:31
-
-
Save lwilli/1ce8be03e5d3721499b7b482b7ec0c21 to your computer and use it in GitHub Desktop.
Like ls, but lists files' last git modification date
This file contains hidden or 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
#! /bin/sh | |
# Like ls, but lists files' last git modification date | |
# Adapated from https://stackoverflow.com/a/73512835/3345085 | |
# To easily create a git alias for this, import it into your git config by running: | |
# echo "git config --global alias.ls $(printf '%q' "`echo -n \!; cat ~/scripts/git-ls.sh`")" | bash - | |
for i in *; | |
do | |
ls -ld $i | awk 'BEGIN { ORS="";} {print $1, $2, $3, $4; printf("%7s ",$5)}'; | |
gd=$(git log -1 --date=local --format="%ad" -- "$i"); | |
if [ -z "$gd" ] ; | |
then printf " --------------------------- $i\n"; # no git date for this file | |
else | |
dfmt="%a %b %d %T %Y"; | |
printf "$(date -j -f "$dfmt" "$gd" "%+%Y") "; | |
ls -d --color=always "$i"; | |
fi; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment