Skip to content

Instantly share code, notes, and snippets.

@lwilli
Created January 30, 2023 20:31
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 lwilli/1ce8be03e5d3721499b7b482b7ec0c21 to your computer and use it in GitHub Desktop.
Save lwilli/1ce8be03e5d3721499b7b482b7ec0c21 to your computer and use it in GitHub Desktop.
Like ls, but lists files' last git modification date
#! /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