scripts!
This commit is contained in:
parent
71ca7eacec
commit
12a111d877
98
README.md
98
README.md
@ -0,0 +1,98 @@
|
||||
# calendarender
|
||||
### and also calendarchive
|
||||
|
||||
These are 2 scripts for calendaring in plantext files. calendar.txt shows the current day at the top and continues down as far as the number of months you have rendered.
|
||||
|
||||
calendar_archive.txt contains all the days before current day.
|
||||
|
||||
It looks like this:
|
||||
|
||||
|
||||
☼ sun nov 29
|
||||
water plants
|
||||
coop fed potluck
|
||||
|
||||
|
||||
◯ mon nov 30
|
||||
recycling
|
||||
|
||||
|
||||
———— December ————
|
||||
|
||||
☼ tue dec 01
|
||||
reading group
|
||||
|
||||
|
||||
☼ wed dec 02
|
||||
1pm appointment
|
||||
|
||||
|
||||
⇃◌ thu dec 03
|
||||
open hours at lab
|
||||
|
||||
|
||||
|
||||
## installation
|
||||
1. clone or download the repo.
|
||||
|
||||
2. configure calendarender by opening the file in your texteditor of choice and modify the line:
|
||||
|
||||
`calendarFile="/Users/YOU/WHEREYOURNOTESARE/calendar.txt"`
|
||||
|
||||
to say where your calendar file is. This must be the absolute path to your calendar file. If you don't have one just make an empty txt file there to start.
|
||||
|
||||
You might also like to configure recurring events. There is SERIOUS ROOM FOR IMPROVEMENT in this. It really ought to be in a separate config file. BUT ALAS, as it is, recurring events are hardcoded. So, if you have things that happen weekly or monthly and you want them to be auto-rendered, you'll need to modify this code block:
|
||||
|
||||
```
|
||||
#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 th>
|
||||
```
|
||||
Anytime something is echoed it goes in the file. Make sure not to get rid of the section `sunday=$(($sunday+1))` because that is how the program keeps track of which sunday (etc) we're on.
|
||||
|
||||
|
||||
|
||||
3. configure calendarchive
|
||||
|
||||
`calendarFile="/Users/YOU/YOURNOTESFOLDER/calendar.txt"`
|
||||
`calendarchive="/Users/YOU/YOURNOTESFOLDER/calendar_archive.txt"`
|
||||
make sure both those exist at least as blank files.
|
||||
|
||||
you might need to `chmod +x` each of the scripts to make sure they're executable.
|
||||
|
||||
4. You can now just run them with `sh calendarchive.sh` or `sh calendarender.sh' but they're easier to use if they're in your path. Copy the scripts somewhere like `~/bin` and add `export PATH=$PATH:~/bin` to `~/.bashrc`
|
||||
|
||||
|
||||
## usage
|
||||
|
||||
### calendarender
|
||||
|
||||
calendarender takes one argument and that's the number of months in the future you'd like to render. So say it's currently a day in November and I want to add the days in January to my calendar.txt.
|
||||
I would run `calendarender 2`. It'll print to the terminal as well as to the file.
|
||||
|
||||
|
||||
### calendarchive
|
||||
|
||||
if you run calendarchive as it is it will remove all days from calendar.txt that are before the current day and append them to the bottom of calendar_archive.txt. If it's late at night but before midnight you can run `calendarchive 1` and it'll also archive today.
|
||||
|
||||
you could cron calendarchive to have it automatically run but personally I keep all kinds of notes and things in my calendar and don't want to lose track of anything. So I manually run calendarchive.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
36
calendarchive.sh
Normal file
36
calendarchive.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/bin/bash
|
||||
#trav's calendarchive program, teafry.me
|
||||
numlines=0
|
||||
calendarFile="/Users/YOU/YOURNOTESFOLDER/calendar.txt"
|
||||
calendarchive="/Users/YOU/YOURNOTESFOLDER/calendar_archive.txt"
|
||||
currentline="$(head -n 1 $calendarFile)"
|
||||
|
||||
#if you pass 1 it'll also move today as well
|
||||
if [[ $1 = 1 ]]
|
||||
then
|
||||
echo "oh, 1 eh? Doin today too then..."
|
||||
currentdate="$(date -v+1d +%a\ %b\ %d | tr '[:upper:]' '[:lower:]')"
|
||||
else
|
||||
currentdate="$(date +%a\ %b\ %d | tr '[:upper:]' '[:lower:]')"
|
||||
fi
|
||||
|
||||
echo "now calendarchiving every day before" $currentdate
|
||||
|
||||
#iterate through calendar.txt, archiving each line until current line contains the current date
|
||||
while [[ "$currentline" != *"$currentdate"* ]];
|
||||
do
|
||||
#put top line of calendar into archive
|
||||
echo "$currentline" >> $calendarchive
|
||||
|
||||
#delete top line of calendar
|
||||
tail -n +2 "$calendarFile" > "$calendarFile.tmp" && mv "$calendarFile.tmp" "$calendarFile"
|
||||
|
||||
#get next line of calendar
|
||||
currentline="$(head -n 1 $calendarFile)"
|
||||
|
||||
#increment # of lines for verbose output
|
||||
numlines=$((numlines + 1))
|
||||
|
||||
done
|
||||
|
||||
echo "moved $numlines lines"
|
93
calendarender.sh
Executable file
93
calendarender.sh
Executable file
@ -0,0 +1,93 @@
|
||||
#!/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
|
||||
#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
|
||||
|
||||
#every monday
|
||||
if [ "$dayOfWeek" = "Mon" ]; then echo "contact Bob">> $calendarFile; echo "put recycling out">> $calendarFile; monday=$(($monday+1)); fi
|
||||
|
||||
#every tuesday
|
||||
if [ "$dayOfWeek" = "Tue" ]; then tuesday=$(($tuesday+1)); fi
|
||||
|
||||
#every wednesday
|
||||
if [ "$dayOfWeek" = "Wed" ]; then wednesday=$(($wednesday+1)); fi
|
||||
|
||||
#every thursday
|
||||
if [ "$dayOfWeek" = "Thu" ]; then echo "open hours at Lab B">> $calendarFile; thursday=$(($thursday+1)); fi
|
||||
|
||||
#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
|
Loading…
Reference in New Issue
Block a user