more months preview

This commit is contained in:
Ämin Baumeler 2025-06-11 12:28:35 +02:00
parent afdf8430d0
commit 9e59e7a923

View File

@ -449,6 +449,30 @@ if [ "${1:-}" = "--preview" ]; then
exit exit
fi fi
month_previous() {
month="$1"
year="$2"
if [ "$month" -eq 1 ]; then
month=12
year=$((year - 1))
else
month=$((month - 1))
fi
echo "$month $year"
}
month_next() {
month="$1"
year="$2"
if [ "$month" -eq 12 ]; then
month=1
year=$((year + 1))
else
month=$((month + 1))
fi
echo "$month $year"
}
if [ "${1:-}" = "--preview-week" ]; then if [ "${1:-}" = "--preview-week" ]; then
sign=$(echo "$2" | cut -d '|' -f 1) sign=$(echo "$2" | cut -d '|' -f 1)
if [ "$sign" = "+" ]; then if [ "$sign" = "+" ]; then
@ -461,23 +485,27 @@ if [ "${1:-}" = "--preview-week" ]; then
year_cur=$1 year_cur=$1
month_cur=$2 month_cur=$2
day_cur=$3 day_cur=$3
# Previous month # Previous months
if [ "$month" -eq 1 ]; then set -- $(month_previous "$month" "$year")
month_pre=12 month_pre="$1"
year_pre=$((year - 1)) year_pre="$2"
else set -- $(month_previous "$month_pre" "$year_pre")
month_pre=$((month - 1)) month_pre2="$1"
year_pre=$year year_pre2="$2"
fi # Next months
# Next month set -- $(month_next "$month" "$year")
if [ "$month" -eq 12 ]; then month_nex="$1"
month_nex=1 year_nex="$2"
year_nex=$((year + 1)) set -- $(month_next "$month_nex" "$year_nex")
else month_nex2="$1"
month_nex=$((month + 1)) year_nex2="$2"
year_nex=$year set -- $(month_next "$month_nex2" "$year_nex2")
fi month_nex3="$1"
year_nex3="$2"
# Highlight today # Highlight today
if [ "$month_pre2" -eq "$month_cur" ] && [ "$year_pre2" -eq "$year_cur" ]; then
var_pre2=$day_cur
fi
if [ "$month_pre" -eq "$month_cur" ] && [ "$year_pre" -eq "$year_cur" ]; then if [ "$month_pre" -eq "$month_cur" ] && [ "$year_pre" -eq "$year_cur" ]; then
var_pre=$day_cur var_pre=$day_cur
fi fi
@ -487,11 +515,20 @@ if [ "${1:-}" = "--preview-week" ]; then
if [ "$month_nex" -eq "$month_cur" ] && [ "$year_nex" -eq "$year_cur" ]; then if [ "$month_nex" -eq "$month_cur" ] && [ "$year_nex" -eq "$year_cur" ]; then
var_nex=$day_cur var_nex=$day_cur
fi fi
if [ "$month_nex2" -eq "$month_cur" ] && [ "$year_nex2" -eq "$year_cur" ]; then
var_nex2=$day_cur
fi
if [ "$month_nex3" -eq "$month_cur" ] && [ "$year_nex3" -eq "$year_cur" ]; then
var_nex3=$day_cur
fi
# show # show
( (
cal "$month_pre2" "$year_pre2" | awk -v cur="${var_pre2:-}" "$AWK_CAL"
cal "$month_pre" "$year_pre" | awk -v cur="${var_pre:-}" "$AWK_CAL" cal "$month_pre" "$year_pre" | awk -v cur="${var_pre:-}" "$AWK_CAL"
cal "$month" "$year" | awk -v cur="${var:-}" -v day="$day" "$AWK_CAL" cal "$month" "$year" | awk -v cur="${var:-}" -v day="$day" "$AWK_CAL"
cal "$month_nex" "$year_nex" | awk -v cur="${var_nex:-}" "$AWK_CAL" cal "$month_nex" "$year_nex" | awk -v cur="${var_nex:-}" "$AWK_CAL"
cal "$month_nex2" "$year_nex2" | awk -v cur="${var_nex2:-}" "$AWK_CAL"
cal "$month_nex3" "$year_nex3" | awk -v cur="${var_nex3:-}" "$AWK_CAL"
) | awk '{ l[NR%8] = l[NR%8] " " $0 } END {for (i in l) if (i>0) print l[i] }' ) | awk '{ l[NR%8] = l[NR%8] " " $0 } END {for (i in l) if (i>0) print l[i] }'
fi fi
exit exit