I use these scripts as my calendar.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

#!/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"