Updated todo_rollover to support force flag

This commit is contained in:
connor committed 2026-09-22 10:35:08 -04:00
1 parent 56c9d4a4d7
commit ec5b9b3c0d
1 file changed
+15 -4
+15 -4
View File
@@ -1,9 +1,10 @@
#!/usr/bin/env bash
# On-demand rollover of a todo note.
# By default copies yesterday's note to today, pruning finished work and retitling.
# Usage: todo_rollover [source_date] [target_date]
# Usage: todo_rollover [--force] [source_date] [target_date]
# source_date defaults to yesterday (YYYY-MM-DD)
# target_date defaults to today
# --force overwrites an existing target
# Set TODO_NOTES to override notes directory.
# Set TODO_PRUNE to override prune script.
@@ -12,8 +13,18 @@ set -euo pipefail
NOTES=${TODO_NOTES:-$HOME/docs/notes/todo}
PRUNE=${TODO_PRUNE:-$HOME/.local/lib/todo/prune.py}
src_date=${1:-$(date -d yesterday +%Y-%m-%d)}
target_date=${2:-$(date +%Y-%m-%d)}
force=0
args=()
for a in "$@"; do
if [[ $a == --force ]]; then
force=1
else
args+=("$a")
fi
done
src_date=${args[0]:-$(date -d yesterday +%Y-%m-%d)}
target_date=${args[1]:-$(date +%Y-%m-%d)}
src="$NOTES/$src_date.md"
dst="$NOTES/$target_date.md"
@@ -23,7 +34,7 @@ if [[ ! -f $src ]]; then
exit 1
fi
if [[ -f $dst ]]; then
if [[ -f $dst && $force -eq 0 ]]; then
echo "todo_rollover: target $dst already exists, skipping (use --force to overwrite)" >&2
echo " Existing target was created from a previous rollover. If you really want to replace it, remove it first." >&2
exit 2