Created
April 20, 2025 18:54
-
-
Save jkuri/89aed5498e5fb0b39c2a424f45d71daa to your computer and use it in GitHub Desktop.
Revisions
-
jkuri created this gist
Apr 20, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ #!/bin/bash # Current month # ./git-worklog.sh # Specific month and year # ./git-worklog.sh --month 3 --year 2025 # Custom output file # ./git-worklog.sh --month 3 --year 2025 --output april-2025-worklog.md REPO_PATH="." cd "$REPO_PATH" || exit 1 MONTH="" YEAR="" OUTPUT_FILE="worklog.md" EMAIL="" while [[ $# -gt 0 ]]; do case $1 in --month) MONTH="$2" shift 2 ;; --year) YEAR="$2" shift 2 ;; --output) OUTPUT_FILE="$2" shift 2 ;; *) echo "Unknown option: $1" exit 1 ;; esac done read -rp "Enter your email: " EMAIL AUTHOR_NAME=$(git log --author="$EMAIL" --format='%an' --reverse | head -n 1) [[ -z "$AUTHOR_NAME" ]] && AUTHOR_NAME="Unknown Author" if [[ -z "$MONTH" ]]; then START_DATE=$(date +%Y-%m-01) MONTH=$(date +%-m) YEAR=$(date +%Y) END_DATE="now" else if (( MONTH < 10 )); then MONTH="0$MONTH" fi [[ -z "$YEAR" ]] && YEAR=$(date +%Y) START_DATE="${YEAR}-${MONTH}-01" END_DATE=$(date -j -f "%Y-%m-%d" "$START_DATE" "+%Y-%m-01" | date -v+1m -v-1d "+%Y-%m-%d") fi MONTH_NAME=$(date -j -f "%m" "$MONTH" "+%B") echo "# Work Specifications for $MONTH_NAME $YEAR" > "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" echo "Author: $AUTHOR_NAME <$EMAIL>" >> "$OUTPUT_FILE" echo "" >> "$OUTPUT_FILE" git log --author="$EMAIL" --since="$START_DATE" --until="$END_DATE" \ --pretty=format:'%h|%ci|%s' | sort -t'|' -k2 | while IFS="|" read -r hash datetime subject; do raw_date=$(echo "$datetime" | cut -d' ' -f1) if formatted_date=$(date -jf "%Y-%m-%d" "$raw_date" "+%A %-d.%m.%Y" 2>/dev/null); then echo "$raw_date|$formatted_date|$hash|$subject" fi done | sort -t'|' -k1 | awk -F'|' -v outfile="$OUTPUT_FILE" ' BEGIN { last_day = "" } { if ($1 != last_day) { if (last_day != "") print "" >> outfile print "## " $2 "\n" >> outfile last_day = $1 } printf "- (%s) %s\n", $3, $4 >> outfile } ' echo "✅ Worklog saved to $OUTPUT_FILE"