Files
calendarender/calendarender.sh

117 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
#calendarender by trav, teafry.me
#moon phase program adapted from https://gist.github.com/smithje/5312617#file-current_moon_phase-sh
get_phase_day () {
local lp=2551443
local now=$1
local newmoon=592500
local phase=$((($now - $newmoon) % $lp))
echo $(((phase / 86400) + 1))
}
get_moon_icon () {
theday=$1
local phase_number=$(get_phase_day $theday)
if [ $phase_number = 1 ]; then phase_icon="●" # new
elif [ $phase_number = 3 ]; then phase_icon="↿☽" # waxing crescent
elif [ $phase_number = 7 ]; then phase_icon="↿◐" # first quarter
elif [ $phase_number = 11 ]; then phase_icon="↿◌" # waxing gibbous
elif [ $phase_number = 15 ]; then phase_icon="◯" # full
elif [ $phase_number = 19 ]; then phase_icon="⇃◌" # waning gibbous
elif [ $phase_number = 23 ]; then phase_icon="⇃◑" # last quarter
elif [ $phase_number = 27 ]; then phase_icon="⇃☾" # waning crescent
else phase_icon="☼" # a SUN day :)
fi
echo $phase_icon
}
OUTPUT="$(date -v+$1m +%B", "%Y)"
read -n 1 -s -r -p "press any key to calendarender ${OUTPUT}"
#INIT VARS#
#the month we are iterating over
CURRENTMONTH="$(date -v+$1m -v1d +%B)"
#one month too far
tooFarNum=$(($1 + 1))
#just the name of the month that is too far
TOOFAR="$(date -v+"$tooFarNum"m +%B)"
#int of days through month
PLACEINMONTH=0
#for keeping track of what number of each day of the week
declare var{sunday,monday,tuesday,wednesday,thursday,friday,saturday}=0
#where the calendar is
calendarFile="/Users/YOU/WHEREYOURNOTESARE/calendar.txt"
#render month title
echo "———— $(date -v+$1m +%B) ————" >> $calendarFile
#iterate through the month
while [ "$CURRENTMONTH" != "$TOOFAR" ];
do
#get lunar icon for the day
dayforlunar=$(date -v+"$1"m -v1d -v+"$PLACEINMONTH"d +%s)
moonicon=$(get_moon_icon $dayforlunar)
#render the icon and day in lowercase to the calendar file
echo "$moonicon $(date -v+"$1"m -v1d -v+"$PLACEINMONTH"d +%a\ %b\ %d)"
printf "\n\n$moonicon $(date -v+"$1"m -v1d -v+"$PLACEINMONTH"d +%a\ %b\ %d)\n" | tr '[:upper:]' '[:lower:]' >> $calendarFile
#current day of the week
dayOfWeek="$(date -v+"$1"m -v1d -v+"$PLACEINMONTH"d +%a)"
############# render weekly things
# SUNDAYS
#every sunday
if [ "$dayOfWeek" = "Sun" ]; then echo "water plants">> $calendarFile; sunday=$(($sunday+1)); fi
#second sunday
if [ "$dayOfWeek" = "Sun" ] && [ "$sunday" -eq 2 ]; then echo "example potluck">> $calendarFile; fi
#3rd sunday
if [ "$dayOfWeek" = "Sun" ] && [ "$sunday" -eq 3 ]; then echo "example potluck on third sunday">> $calendarFile; fi
#last sunday
if [ "$(date -v1d -v+"$tooFarNum"m -v-1d -v-sun +%a-%b-%d)" = "$(date -v1d -v+"$1"m -v+"$PLACEINMONTH"d +%a-%b-%d)" ] && [ "$dayOfWeek" = "Sun" ]; then echo "last sunday of the month potluck">> $calendarFile; fi
# MONDAYS
#every monday
if [ "$dayOfWeek" = "Mon" ]; then echo "contact Bob">> $calendarFile; echo "put recycling out">> $calendarFile; monday=$(($monday+1)); fi
# TUESDAYS
#every tuesday
if [ "$dayOfWeek" = "Tue" ]; then tuesday=$(($tuesday+1)); fi
# WEDNESDAYS
#every wednesday
if [ "$dayOfWeek" = "Wed" ]; then wednesday=$(($wednesday+1)); fi
# THURSDAYS
#every thursday
if [ "$dayOfWeek" = "Thu" ]; then echo "open hours at Lab B">> $calendarFile; thursday=$(($thursday+1)); fi
# FRIDAYS
#every friday
if [ "$dayOfWeek" = "Fri" ]; then friday=$(($friday+1)); fi
# SATURDAYS
#every saturday
if [ "$dayOfWeek" = "Sat" ]; then saturday=$(($saturday+1)); fi
#increment through month
PLACEINMONTH=$(($PLACEINMONTH+1))
CURRENTMONTH=$(date -v+"$1"m -v1d -v+"$PLACEINMONTH"d +%B)
done