Created
November 1, 2018 08:07
-
-
Save Cloudo/b1a50b1b709d1731071d3fb98353f335 to your computer and use it in GitHub Desktop.
bash script to log git commits grouped by day
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/bash | |
# Generates git changelog grouped by day | |
# | |
# optional parameters | |
# -a, --author to filter by author | |
# -s, --since to select start date | |
# -u, --until to select end date | |
git-timesheet () { | |
local NEXT=$(date +%F) | |
local RED="\x1B[31m" | |
local YELLOW="\x1B[32m" | |
local BLUE="\x1B[34m" | |
local RESET="\x1B[0m" | |
local SINCE="1970-01-01" | |
local UNTIL=$NEXT | |
for i in "$@" | |
do | |
case $i in | |
-a=*|--author=*) | |
local AUTHOR="${i#*=}" | |
shift | |
;; | |
-s=*|--since=*) | |
SINCE="${i#*=}" | |
shift | |
;; | |
-u=*|--until=*) | |
UNTIL="${i#*=}" | |
shift | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
local LOG_FORMAT=" %Cgreen*%Creset %s" | |
if [ -z "$AUTHOR" ] | |
then | |
LOG_FORMAT="$LOG_FORMAT %Cblue(%an)%Creset" | |
else | |
echo | |
echo -e "${BLUE}Logs filtered by author: ${AUTHOR}${RESET}" | |
fi | |
git log --all --no-merges --author="${AUTHOR}" --since="${SINCE}" --until="${UNTIL}" --format="%cd" --date=short | sort -u | while read DATE ; do | |
local GIT_PAGER=$(git log --all --no-merges --reverse --format="${LOG_FORMAT}" --since="${DATE} 00:00:00" --until="${DATE} 23:59:59" --author="${AUTHOR}") | |
if [ ! -z "$GIT_PAGER" ] | |
then | |
echo | |
echo -e "${RED}[$DATE]${RESET}" | |
echo -e "${GIT_PAGER}" | |
fi | |
done | |
} | |
git-timesheet "$@" | less -R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment