Initial commit

This commit is contained in:
Keith Irwin 2024-07-21 18:55:40 -06:00
commit 53c38d6aea
Signed by: ki9
GPG Key ID: DF773B3F4A88DA86
5 changed files with 70 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Environment
env

9
LICENSE Normal file
View File

@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright © 2024 Keith Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# mktodo
Create todo lists for every day.
## Installation
TODO

10
env.sample Executable file
View File

@ -0,0 +1,10 @@
# Where to store these todo lists
NOTES_DIR="~/todo"
# Where to archive completed lists
ARCHIVE_DIR="${NOTES_DIR}/archive/"
# Template for things to do each day
DAILY_TEMPLATE="${NOTES_DIR}/template.md"
# Template for things to do each month
MONTHLY_TEMPLATE="${NOTES_DIR}/monthly.md"
# What day each month to add the monthly list
MONTHLY_TEMPLATE_DATE='01'

42
mktodo Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash -u
# mktodo
# Script to refresh todo lists
source "./env"
umask 027
# Create missing lists up to one month from today
for num_days in {01..30}; do
next_date="$(date -I --date=${num_days}days)"
next_list="${NOTES_DIR}/${next_date}.md"
# Todo file for day doesn't exist
if ! [ -f "${next_list}" ]; then
# Copy template over
sed "1i# $(date --date "${next_date}" +%A)" "${DAILY_TEMPLATE}" \
>${next_list} && printf 'Created list for %s.\n' "${next_date}"
# Add monthly todo
if [ "${next_date:(-2)}" == "${MONTHLY_TEMPLATE_DATE}" ]; then
cat "${MONTHLY_TEMPLATE}" >>"${next_list}" \
&& printf 'Added monthly todos to %s\n' "${next_list}"
fi
fi
done
# Archive past days
for file in $(find "${NOTES_DIR}" -maxdepth 1 -type f -name '*-*-*.md'); do
this_date="$(basename ${file} | cut -d. -f1)"
# This file is in the past
if [ $(date --date '0:00' +%s) -gt $(date --date "${this_date}" +%s) ]; then
# Check for undone items
if grep -q '\[ \]' ${file}; then
printf 'NOT archiving %s because it has unfinished tasks!\n' "${this_date}.md"
else
mv "${file}" "${ARCHIVE_DIR}" \
&& printf 'Archived %s.\n' "${this_date}.md"
fi
fi
done