Skip to content

Instantly share code, notes, and snippets.

@gukandrew
Created August 25, 2020 12:21
Show Gist options
  • Save gukandrew/ed99081fb91d8579ee2746718d29e4a3 to your computer and use it in GitHub Desktop.
Save gukandrew/ed99081fb91d8579ee2746718d29e4a3 to your computer and use it in GitHub Desktop.
Script that shows list of files and last change in git for them, files could be passed as params
#!/bin/sh
# Shows list of files and last change in git for them
# USAGE:
# ~/gw.sh [optional: <file1> <file2> ... otherwise current dir will be used]
# complex example
# bash -c "~/gw.sh $(git ls-tree -r --name-only HEAD app/*/web/main.js | tr '\n' ' ')"
#
# based on: https://stackoverflow.com/a/17361406
FILES=("$@")
if [ $# -eq 0 ]; then
echo "Running on current dir"
FILES="$(git ls-tree --name-only HEAD .)"
fi
MAXLEN=0
IFS="$(printf "\n\b")"
for f in ${FILES[@]}; do
if [ ${#f} -gt $MAXLEN ]; then
MAXLEN=${#f}
fi
done
for f in ${FILES[@]}; do
str="$(git log -1 --pretty=format:"%C(green)%cr%Creset %x09 %C(cyan)%h%Creset %s %C(yellow)(%cn)%Creset" $f)"
printf "%-${MAXLEN}s -- %s\n" "$f" "$str"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment