commit d18cecdd36d46a4e66fc0e57cefe36fd7b5346a0
parent 393ddb3e51a1ea2c688344c04dc77c9eea05cb5a
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Tue, 9 Dec 2025 15:13:31 +0100
fix: robustness regarding empty months
Diffstat:
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/activity.sh b/activity.sh
@@ -1,6 +1,6 @@
#!/usr/bin/env sh
# SPDX-License-Identifier: AGPL-3.0-or-later
-# SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
+# SPDX-FileCopyrightText: 2024-2025 JayVii <jayvii[AT]posteo[DOT]de>
# Configuration ----------------------------------------------------------------
@@ -22,15 +22,15 @@ html_output() {
OPC="$3"
TTL=""
# if date is present, add it to the title
- if [ ! -z $DTE ]; then
+ if [ ! -z "$DTE" ]; then
TTL=${TTL}$(date --date "${DTE}-01" "+%b, %Y");
fi
# if date and comment are present, add separator to the title
- if [ ! -z $DTE ] && [ ! -z $CMT ]; then
+ if [ ! -z "$DTE" ] && [ ! -z "$CMT" ]; then
TTL="${TTL}: "
fi
# if comment is present, add it to the title
- if [ ! -z $CMT ]; then TTL="${TTL}${CMT} commits"; fi
+ if [ ! -z "$CMT" ]; then TTL="${TTL}${CMT} commits"; fi
# re-scale opacity linearly between 10-100
OPC=$(echo "(($OPC * 90) / 100) + 10" | bc)
# create HTML arguments
@@ -51,7 +51,7 @@ for DIR in $DIRS; do
git \
-C $DIR \
log --date=short --pretty=format:%ad | \
- awk '{print substr($1, 1, 7)}'
+ sed -E -e 's/^([0-9]{4}-[0-9]{2})-.*$/\1/g'
)\n"
done
@@ -66,31 +66,31 @@ AGGREGATE=$(
# get timeframe
MIN_TIME=$(echo "$AGGREGATE" | head -n 1 | awk '{ print $NF }')
-MAX_TIME=$(date +%Y-%m -d "next month")
+MAX_TIME=$(date +%Y-%m)
# get value range
MIN_VAL=0
MAX_VAL=$(echo "$AGGREGATE" | awk '{ print $1 }' | sort -n | tail -n 1)
-if [ -z $MAX_VAL ]; then MAX_VAL=1; fi
+if [ -z "$MAX_VAL" ]; then MAX_VAL=1; fi
# Generate output --------------------------------------------------------------
# initilise html
MIN_TIME_PRETTY=$(date --date "${MIN_TIME}-01" "+%b, %Y")
-MAX_TIME_PRETTY=$(date --date "${MAX_TIME}-01 -1 day" "+%b, %Y")
+MAX_TIME_PRETTY=$(date --date "${MAX_TIME}-01" "+%b, %Y")
HTML="<h6>Activity: ${MIN_TIME_PRETTY} - ${MAX_TIME_PRETTY}</h6>"
# cycle through months from earliest timepoint
CUR_TIME=$MIN_TIME
-while [ $CUR_TIME != $MAX_TIME ]; do
+while [ "$CUR_TIME" != "$MAX_TIME" ]; do # FIXME: break occurs here
# fetch current value
CUR_VAL=$(echo "$AGGREGATE" | grep $CUR_TIME | awk '{ print $1 }')
- if [ -z $CUR_VAL ]; then CUR_VAL=0; fi
+ if [ -z "$CUR_VAL" ]; then CUR_VAL=0; fi
# normalise current value [0, 100]
NRM_VAL=$(echo "${CUR_VAL} * 100 / ${MAX_VAL}" | bc)
- if [ -z $NRM_VAL ]; then NRM_VAL=0; fi
+ if [ -z "$NRM_VAL" ]; then NRM_VAL=0; fi
# output HTML
HTML=${HTML}$(html_output "$CUR_TIME" "$CUR_VAL" "$NRM_VAL")