scripts!
This commit is contained in:
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"
|
||||
Reference in New Issue
Block a user