commit 63d69fa5922c1121bc70492293299a4400306fc4
parent c4aa889eb1a8a7041e5f40d6ba6cfb8d98485a5c
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date: Sun, 9 Feb 2025 12:10:39 +0100
fix: rewrite for POSIX shell
Diffstat:
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/activity.sh b/activity.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
# SPDX-License-Identifier: AGPL-3.0-or-later
# SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
@@ -15,23 +15,24 @@ DIRS="$@"
# Output Functions -------------------------------------------------------------
# HTML output
-function html_output {
+html_output() {
# grab function input
DTE="$1"
CMT="$2"
OPC="$3"
+ TTL=""
# if date is present, add it to the title
- if [[ ! -z $DTE ]]; then
- TTL+=$(date --date "${DTE}-01" "+%b, %Y");
+ 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
- TTL+=": "
+ if [ ! -z $DTE ] && [ ! -z $CMT ]; then
+ TTL="${TTL}: "
fi
# if comment is present, add it to the title
- if [[ ! -z $CMT ]]; then TTL+="$CMT commits"; fi
+ if [ ! -z $CMT ]; then TTL="${TTL}${CMT} commits"; fi
# re-scale opacity linearly between 10-100
- OPC=$(((($OPC * 90) / 100) + 10))
+ OPC=$(echo "(($OPC * 90) / 100) + 10" | bc)
# create HTML arguments
ID="activity-$DTE"
CL="activitypoint"
@@ -44,8 +45,9 @@ function html_output {
# Collect activity -------------------------------------------------------------
# By Months
+ACTIVITY=""
for DIR in $DIRS; do
- ACTIVITY+="$(
+ ACTIVITY="${ACTIVITY}$(
git \
-C $DIR \
log --date=short --pretty=format:%ad | \
@@ -79,19 +81,19 @@ 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
# fetch current value
CUR_VAL=$(echo "$AGGREGATE" | grep $CUR_TIME | awk '{ print $1 }')
# normalise current value [0, 100]
- NRM_VAL=$((${CUR_VAL:-0} * 100 / ${MAX_VAL:-1}))
+ NRM_VAL=$(echo "${CUR_VAL:-0} * 100 / ${MAX_VAL:-1}" | bc)
# list data in variable
# DATA+="$CUR_TIME ${CUR_VAL:-0} ${NRM_VAL:-5}\n"
# output HTML
- HTML+=$(html_output "$CUR_TIME" ${CUR_VAL:-0} ${NRM_VAL:-0})
+ HTML=${HTML}$(html_output "$CUR_TIME" ${CUR_VAL:-0} ${NRM_VAL:-0})
# update current time
CUR_TIME=$(date --date "${CUR_TIME}-01 +1 month" +%Y-%m)
@@ -103,17 +105,17 @@ while [ $CUR_TIME != $MAX_TIME ]; do
done
# add legend
-HTML+="<br><p id=\"activitylegend\">Less "
+HTML="${HTML}<br><p id=\"activitylegend\">Less "
for LV in $(seq 0 25 100); do
# Calculate label value
LND_VAL=$(($LV * $MAX_VAL / 100))
# Generate HTML
- HTML+=$(html_output "" $LND_VAL $LV)
+ HTML=${HTML}$(html_output "" $LND_VAL $LV)
done
-HTML+=" More</p>"
+HTML="${HTML} More</p>"
# add "activitybar" div
HTML="<div id=\"activitybar\">$HTML</div>"