Last active
November 17, 2023 12:19
-
-
Save phranck/cb6384e74661b4c971fd272fdc5fa670 to your computer and use it in GitHub Desktop.
Generates a structured list of Git commits by a dedicated user over a time period
This file contains 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 | |
# ======================================== | |
# ANSI Color escape codes: | |
# ======================================== | |
# Black 0;30 Dark Gray 1;30 | |
# Red 0;31 Light Red 1;31 | |
# Green 0;32 Light Green 1;32 | |
# Brown/Orange 0;33 Yellow 1;33 | |
# Blue 0;34 Light Blue 1;34 | |
# Purple 0;35 Light Purple 1;35 | |
# Cyan 0;36 Light Cyan 1;36 | |
# Light Gray 0;37 White 1;37 | |
BLACK='\033[0;30m' | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
ORANGE='\033[0;33m' | |
BLUE='\033[0;34m' | |
PURPLE='\033[0;35m' | |
CYAN='\033[0;36m' | |
LGRAY='\033[0;37m' | |
DGRAY='\033[1;30m' | |
LRED='\033[1;31m' | |
LGREEN='\033[1;32m' | |
YELLOW='\033[1;33m' | |
LBLUE='\033[1;34m' | |
LPURPLE='\033[1;35m' | |
LCYAN='\033[1;36m' | |
WHITE='\033[1;37m' | |
NC='\033[0m' # No Color | |
ACTUAL_DIR=$(pwd) | |
# Check if a path to a repository was given | |
[ $# -ne 1 ] && echo "Usage: $0 </path/to/your/repository>" 1>&2 && exit 1 | |
cd "$1" | |
# Ask for name of the author which should be used for the filter | |
DEFAULT_AUTHOR=$(git config --get user.name) | |
printf "Git user to filter (default: $DEFAULT_AUTHOR): " | |
read AUTHOR | |
if [[ -z "${AUTHOR}" ]]; then | |
AUTHOR=${DEFAULT_AUTHOR} | |
fi | |
# Ask for year to filter | |
DEFAULT_YEAR=$(date +%Y) | |
printf "Enter the year to filter (default: ${DEFAULT_YEAR}): " | |
read YEAR | |
if [[ -z "${YEAR}" ]]; then | |
YEAR=${DEFAULT_YEAR} | |
fi | |
#ask for start month | |
DEFAULT_START_MONTH="01" | |
printf "Enter start month to filter (default: ${DEFAULT_START_MONTH}): " | |
read START_MONTH | |
if [[ -z "${START_MONTH}" ]]; then | |
START_MONTH=${DEFAULT_START_MONTH} | |
fi | |
if ! [[ "${START_MONTH}" =~ ^[0-9]+$ ]] ; then | |
echo -e "${RED}ERROR: Not a number!${NC}" | |
exit 1 | |
fi | |
#ask for end month | |
DEFAULT_END_MONTH=$(date +%m) | |
printf "Enter end month to filter (default: ${DEFAULT_END_MONTH}): " | |
read END_MONTH | |
if [[ -z "${END_MONTH}" ]]; then | |
END_MONTH=${DEFAULT_END_MONTH} | |
fi | |
if ! [[ "${END_MONTH}" =~ ^[0-9]+$ ]] ; then | |
echo -e "${RED}ERROR: Not a number!${NC}" | |
exit 1 | |
fi | |
# Here we go... | |
REPO_NAME=$(basename `git rev-parse --show-toplevel`) | |
echo -e "${YELLOW}Git history for: ${AUTHOR}, ${START_MONTH}/${YEAR} - ${END_MONTH}/${YEAR}, Repo: ${REPO_NAME}${NC}" | |
echo | |
MONTH_RANGE=$(seq ${START_MONTH} ${END_MONTH}) | |
for MONTH in $MONTH_RANGE; do | |
MONTH=$(printf "%02d" $MONTH) | |
GIT=$(git log --reverse --date=format-local:'%Y-%m-%d %H:%M:%S' --pretty=format:"%ad: %s" --after="${YEAR}-${MONTH}-01" --until="${YEAR}-${MONTH}-31" --author="${AUTHOR}" 2>&1) | |
if ! [[ -z "$GIT" ]]; then | |
echo -e "${YELLOW}Month: $MONTH/$YEAR${NC}" | |
echo -e "${YELLOW}--------------${NC}" | |
echo "${GIT}" | |
echo | |
echo | |
fi | |
done | |
cd "${ACTUAL_DIR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will produce an output like this: