chore: revamp to fit new standard

This commit is contained in:
Viktor Varland 2023-04-11 17:23:26 +02:00
parent bc2ef9b781
commit 6ff5828ff2
Signed by: varl
GPG key ID: 7459F0B410115EE8
3 changed files with 88 additions and 8 deletions

26
README
View file

@ -1,3 +1,28 @@
generate-year.sh
----------------
usage:
./generate-year [year]
parameter [year] is optional, omit to use current year
user alias:
function te {
local date=${1:-$(date -I)}
local year=$(date -d $date +%Y)
local timedir="$HOME/plan/time"
local archivedir="$timedir/archive"
if [[ $year < $(date +%Y) ]]; then
vim -c "/$date" $archivedir/$year.timedot
fi
vim -c "/$date" $timedir/$year.timedot
}
generate-week.sh generate-week.sh
---------------- ----------------
@ -10,3 +35,4 @@ user alias:
function te () { function te () {
$EDITOR ~/plan/time/current.timedot $EDITOR ~/plan/time/current.timedot
} }

54
generate-year.sh Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euo pipefail
#
## script arguments
#
YEAR="${1:-$(date +%Y)}"
#
## support functions
#
function main () {
local date_year_first="$(date -I -d "${1}-01-01")"
local date_year_last="$(date -I -d "${date_year_first} + 1 year - 1 day")"
local start="$date_year_first"
local stop="$date_year_last"
while ! [[ $start > $stop ]]; do
local weekday=$(date -d "$start" +%u)
local day_name="$(date -d "$start" +%A)"
local base_monday
if [[ $weekday -eq 1 ]]; then
base_monday=$start
else
overshoot=$(($weekday - 1))
base_monday=$(date -I -d "$start -${overshoot}days")
fi
week="$(date -d "$base_monday" +%V)"
echo "$start # ${day_name,,} w:$week"
if [[ \
"$day_name" != "Friday" && \
"$day_name" != "Saturday" && \
"$day_name" != "Sunday" \
]]; then
echo "amedia 8"
fi
if [[ "$day_name" == "Friday" ]]; then
echo "umara 8"
fi
echo ""
start=$(date -I -d "$start + 1 day")
done
}
main $YEAR